Show spinner while clicking on text editing in Android?

when the user clicks the editText field I need to show the spinner (dynamic) from this user, select any element that I need to set for the text to be edited. How to do it?

+3
source share
3 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();
        }
    });
 }
+8
source

You must use AutoCompleteTextView .

+2
source

OnClick TextViewI took the AlertDailog field, consisting of MydataAdapterwhich I passed txt_show.setText(Arraylistdata[which].toString())to show inTextView

Follow this code:

txt_show.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v){
            new AlertDialog.Builder(MyActivity.this)
                    .setTitle("Select More Categories")
                    .setAdapter(MydataAdapter, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                            txt_show.setText(Arraylistdata[which].toString());

                            dialog.dismiss();
                        }
                    }).create().show();
        }
        });
0
source

Source: https://habr.com/ru/post/1776671/


All Articles