Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

show spinner at the time of clicking edit text in Android?

Tags:

android

when the user click the editText Field I need to show spinner(dynamic) from that user select any of the item i need to set the Text for Edit text .How to do this?

like image 241
Tester Avatar asked Dec 18 '25 05:12

Tester


1 Answers

public class Main extends Activity implements OnClickListener{

TextView textview_countries;

private String[] countries_list={"Philippines","Japan","Australia"};
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    textview_countries=(TextView) findViewById(R.id.txtview_countries);
    textview_countries.setInputType(InputType.TYPE_NULL); //To hide the softkeyboard


    final ArrayAdapter<String> spinner_countries = new  ArrayAdapter<String>(Main.this,android.R.layout.simple_spinner_dropdown_item, countries_list);

    textview_countries.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            new AlertDialog.Builder(Main.this)
                  .setTitle("Select Countries")
                  .setAdapter(spinner_countries, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        textview_countries.setText(countries_list[which].toString());
                      dialog.dismiss();
                    }
                  }).create().show();
        }
    });
 }
like image 62
Cjames Avatar answered Dec 20 '25 17:12

Cjames



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!