trancer trancer - 11 days ago 8
Android Question

Android - AutoCompleteTextView not showing after setText is called

I'm having a weird issue with

AutoCompleteTextView
.

I have a
AutoCompleteTextView
that shows suggestions of cities when typing in it.
The list of cities is retrieved from a remote server via
JSON
. When I use the soft keyboard or the
Mic
Button on the soft keyboard, the suggestions work fine.
AutoCompleteTextView
does show the suggested cities.

But, I have a problem when I try to set the text using
myAutoCompleteTextView.setText("Chi")
, the auto complete does not show..
I have also tried
myAutoCompleteTextView.append("Chi")
but still no luck..

The adapter is there, its just that the suggestions don't show.

Any tips?

Thanks.

Answer

Yes you are right there is a bug in AutocompleteTextview to show default suggestion using setText(""); method.

But you can achieve this by adding some more lines of code as below.

autoText.postDelayed(new Runnable() {
            @Override
            public void run() {
                autoText.showDropDown();
            }
        },500);
        autoText.setText("chi");
        autoText.setSelection(autoText.getText().length());