use*_*169 7 android fragment autocompletetextview
我进行了很多搜索并尝试了很多解决方法 - 但似乎都不起作用。
在我的片段中,我有带有标准 ArrayAdapter 的 AutoCompleteTextView,它动态填充 onActivityCreated() 函数(如下所示)。
第一次添加片段时一切正常。然而,在我用另一个片段替换这个片段(带有自动完成功能)后 - 并使用“后退”按钮返回 - 我遇到了“自动完成”停止表现得像“自动完成”的问题 - 所以如果我现在输入它,但是我不再收到“建议下拉菜单”。
值得一提的是,我没有使用设备 softInput 进行打字 - 因为我只需要将手机号码作为输入 - 我在屏幕上显示了自己的自定义键。但我认为这不会造成任何问题。
随附 2 个屏幕截图 - 1)在自动完成工作正常时替换片段之前 2)在替换片段之后并返回,当自动完成停止显示建议时(注意我在这里再次输入“981”)。
欢迎任何帮助!
// '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());
}
}
Run Code Online (Sandbox Code Playgroud)
小智 1
我找到了下一个解决方法:
mAdapter.filter.filter("")
Run Code Online (Sandbox Code Playgroud)
更新时,只需在 addAll 语句之前调用它即可。
希望能帮助到你!这个问题严重困扰了我一段时间。
| 归档时间: |
|
| 查看次数: |
1062 次 |
| 最近记录: |