【发布时间】:2016-03-27 00:12:10
【问题描述】:
我进行了很多搜索并尝试了很多解决方法 - 但似乎没有一个有效。
在我的片段中,我有带有标准 ArrayAdapter 的 AutoCompleteTextView,它在 onActivityCreated() 函数中动态填充(如下所示)。
第一次添加片段时一切正常。然而,在我用另一个片段替换这个片段(使用自动完成)之后 - 并使用“返回”按钮返回 - 我得到的问题是“自动完成”停止表现得像“自动完成” - 所以如果我现在输入它,但是我不再收到“建议下拉菜单”了。
要提一提的是,我没有使用设备 softInput 进行打字——因为我只需要输入手机号码——我在屏幕上显示了自己的自定义键。但我认为这不会造成任何问题。
附件是 2 个屏幕截图 - 1) 替换片段之前自动完成工作正常 2) 替换片段之后返回,当自动完成停止显示建议时(注意我在这里再次输入了“981”)。
after fragment replace - 981 is typed again
欢迎任何帮助!!
// 'mCustMobileNums' is a singleton class which fetches strings stored in a DB table.
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
Log.d(TAG, "In onActivityCreated");
super.onActivityCreated(savedInstanceState);
if (mCustMobileNums==null) {
mCustMobileNums = CustomerMobileNums.getInstance(getActivity().getApplicationContext());
}
initInputCustMobile();
}
private void initInputCustMobile() {
if(mAdapter==null) {
Log.d(TAG, "Creating autocomplete adapter instance.");
mAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_dropdown_item_1line);
mAdapter.addAll(mCustMobileNums.getCollection());
mAdapter.setNotifyOnChange(false);
}
mInputCustMobile.setAdapter(mAdapter);
Log.d(TAG, "Initialized autocomplete adaptor: " + mAdapter.getCount());
}
// This function is called when I have insert new entry in the data set
public void updateAutoCompleteAdaptor(String mobileNum) {
Log.d(TAG,"In updateAutoCompleteAdaptor");
// add in memory and db
// will return TRUE if entry was not already available and added successfully
if( mCustMobileNums.addCustMobileNum(mobileNum) ) {
// recreate with sorted set
mAdapter.clear();
mAdapter.addAll(mCustMobileNums.getCollection());
mAdapter.notifyDataSetChanged();
Log.d(TAG,"Updated autocomplete adaptor: "+mAdapter.getCount());
}
}
【问题讨论】:
-
它是否在不同的设备上执行此操作?某些 Android 版本?
标签: android fragment autocompletetextview