How can I avoid autocomplete dropdown appearing when text is programmatically set?

Chris Knight picture Chris Knight · Sep 18, 2011 · Viewed 8.8k times · Source

I have an AutoCompleteTextView in my layout. I also have an alternative way to select the same items which are present in the AutoCompleteTextView. When the alternative way is selected, I populate the value in the AutoCompleteTextView via:

autoCompleteTextView.setText(valueFromAlternativeSource);

where valueFromAlternativeSource is one of the valid auto complete options. The trouble with this is that the autocomplete dropdown appears when setText is called. Putting the following line after the above doesn't work:

autoCompleteTextView.dismissDropDown();  //Doesn't work.  Why?

Any ideas on why dismiss dropdown isn't working or other ways I could dismiss the dropdown?

Answer

drlue picture drlue · Feb 27, 2013

This works fine for me and is less complex:

ListAdapter adapter = autoCompleteTextView.getAdapter();
autoCompleteTextView.setAdapter(null);
autoCompleteTextView.setText("whatever");
autoCompleteTextView.setAdapter(adapter);