Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine Spinner and AutoCompleteTextView

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?

like image 633
user2710805 Avatar asked Sep 24 '13 13:09

user2710805


People also ask

How to Create AutoCompleteTextView field in XML?

In android, we can create an AutoCompleteTextView control in two ways either manually in an XML file or create it in the Activity file programmatically. First we create a new project by following the below steps: Click on File, then New => New Project. After that include the Kotlin support and click on next.

What does Android completion hint attribute in AutoCompleteTextView does?

android:completionHintView. Defines the hint view displayed in the drop down menu. android:completionThreshold. Defines the number of characters that the user must type before completion suggestions are displayed in a drop down menu.


2 Answers

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();
        }
    });
like image 77
user2710805 Avatar answered Sep 17 '22 06:09

user2710805


Try this code:

 ArrayAdapter myAdapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_dropdown_item_1line, YOUR_ARRAY);
    myAutoCompleteTextView.setAdapter(myAdapter );
like image 31
Vikram Singh Avatar answered Sep 20 '22 06:09

Vikram Singh