Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 282
trancer Avatar asked Jan 28 '15 04:01

trancer


1 Answers

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());
like image 134
Biraj Zalavadia Avatar answered Oct 13 '22 14:10

Biraj Zalavadia