小编Hbi*_*bna的帖子

带有过滤器的Listview将不会刷新,直到键盘被隐藏或按下返回

我有一个列表视图,显示联系人列表.我在listview上方的布局中添加了EditText,因此我可以使用Filter进行搜索.我使用EditText上的onTextChanged Listener实现了这个.我的listview适配器是一个自定义适配器,它扩展了BaseAdapter并实现了Filterable.我的过滤器可以正常工作.问题是,当我输入时,数据集会刷新,但列表视图本身不会刷新,直到我隐藏键盘或按返回键.如果我在EditText中输入一些文本后尝试点击列表视图但在关闭键盘或按回车之前,我收到此错误:

java.lang.IllegalStateException: The content of the adapter has changed 
but ListView did not receive a notification. Make sure the content of 
your adapter is not modified from a background thread, but only from the UI thread.
Run Code Online (Sandbox Code Playgroud)

现在我肯定不会从UI线程以外的线程修改适配器的内容.

谁能解释一下可能导致这个问题的原因?

实际上,我通过调用找到了一种解决方法,Activity.onContentChanged()但我仍然很好奇为什么我实际上需要手动刷新.

android listview filter

4
推荐指数
1
解决办法
1888
查看次数

标签 统计

android ×1

filter ×1

listview ×1