19

I am asking myself if it is possible, to combine a Spinner and a AutoCompleteTextView. Basically I want an AutoCompleteTextView, that shows all entries from Array when I click it.

Does anybody know how to do that?

Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96
user2710805
  • 743
  • 1
  • 5
  • 9

2 Answers2

53

Just found out that this does exactly what I was asking for:

final AutoCompleteTextView textView;
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
            getActivity(), android.R.layout.simple_dropdown_item_1line,
            getResources().getStringArray(R.array.names));

    textView = (AutoCompleteTextView) v.findViewById(R.id.txtViewNames);
    textView.setAdapter(arrayAdapter);
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View arg0) {
            textView.showDropDown();
        }
    });
user2710805
  • 743
  • 1
  • 5
  • 9
  • 1
    Very Good Job Man ! I was looking for exactly the same thing. I wish I could to +10. But what I found is when we type two characters then it shows the options in drop down. But still it is very very nice example. Thanks. – gprathour Jun 06 '14 at 18:42
  • For resolve two character issue, add android:completionThreshold="1" to AutoCompleteTextView. – Himani Aug 17 '21 at 10:18
9

Try this code:

 ArrayAdapter myAdapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_dropdown_item_1line, YOUR_ARRAY);
    myAutoCompleteTextView.setAdapter(myAdapter );
Vikram Singh
  • 1,420
  • 14
  • 19