Combine Spinner and AutoCompleteTextView

user2710805 picture user2710805 · Sep 24, 2013 · Viewed 20.7k times · Source

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?

Answer

user2710805 picture user2710805 · Sep 25, 2013

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();
        }
    });