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?
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.
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.
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();
}
});
Try this code:
ArrayAdapter myAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, YOUR_ARRAY);
myAutoCompleteTextView.setAdapter(myAdapter );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With