如何以编程方式在autocompletetextview中选择项目

时间:2013-11-07 17:22:42

标签: android autocompletetextview

我遇到了与autocompletetextview行为密切相关的问题。 在我的应用程序中,我像往常一样使用AutoCompleteTextView实例:

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

一切都很好,当我开始输入符号时,我会收到Dropdown和国家列表,然后我选择一个国家/地区,这个国家/地区名称出现在EditText中,而DropDown则被取消。 但是当我旋转设备时(我的活动不再重新创建,我在清单中注意到它)Dropdown再次出现,我不得不再次确认我的选择。有什么方法可以避免这种反复行动吗?

编辑#1:如果我能够通过编程方式从下拉列表中模拟项目选择,就像performClick那样将会很好...另一种解决我问题的方法是(正如我所想)在正确的时刻切换适配器并关闭然后在适当的时候打开它,但它需要在片段生命周期中找到适当的时间。

编辑#2:我注意到不同的行为AutoCompleteTextView取决于设备。在Nexus7,三星Note 2上一切都很好,但摩托罗拉Xoom的行为如上所述。

1 个答案:

答案 0 :(得分:1)

尝试在Activity

中使用两种方法
@Override
    public void onConfigurationChanged(Configuration confi) {
        super.onConfigurationChanged(confi);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }
相关问题