Alex  Zezekalo
Alex Zezekalo

Reputation: 1171

How to select item in autocompletetextview programmatically

I`ve got a trouble closely related with autocompletetextview behaviour. In my app I use AutoCompleteTextView instance as usual:

textViewCountry = (AutoCompleteTextView) root.findViewById(R.id.textCountry_Edit);
mCityCursorAdapter = new CityCursorAdapter(getActivity(), cursor);
textViewCountry.setAdapter(mCityCursorAdapter);
textViewCountry.setThreshold(1);

Everything is fine, when I begin input symbols I will receive Dropdown with the list of countries, then I select one of the country and this country name appears in EditText and DropDown is dismissed. But when I rotate device (my activity don`t re-create, I noticed it in manifest) Dropdown appears again and I had to confirm my choice again. Is there any way how to avoid this repeatedly action?

Edit#1: It will be fine if I`m able to simulate item selection from dropdown list programmatically something like performClick... Another way to solve my problem is (as I think) at the right moment switch adapter off and then at the proper time switch it on but it needs to find a proper time in fragment lifecycle.

Edit#2: I noticed different behaviour AutoCompleteTextView depending on devices. Everything is ok on Nexus7, Samsung Note 2, but Motorola Xoom has wierd behaviour as I described above.

Upvotes: 3

Views: 2887

Answers (1)

Amit Gupta
Amit Gupta

Reputation: 8939

Try using two methods in your Activity class

@Override
    public void onConfigurationChanged(Configuration confi) {
        super.onConfigurationChanged(confi);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

Upvotes: 1

Related Questions