Question

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?

Was it helpful?

Solution 2

Try this code:

 ArrayAdapter myAdapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_dropdown_item_1line, YOUR_ARRAY);
    myAutoCompleteTextView.setAdapter(myAdapter );

OTHER TIPS

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();
        }
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top