您的位置:首页 > 其它

解决listview出现线程更新错误问题

2017-12-08 23:30 239 查看

前言

在做项目的过程中,遇到了一个问题:

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.


原因

在执行listview刷新操作时,当listview的adapter中的数据更新了,但是listview还未来得及刷新,这时,你点击了该listview,便会抛出这个异常。

解决方案

设置listview的visibility

listview.setVisibility(View.VISIBLE/View.GONE)


操作

在执行更新listview数据的操作前设置

listView.setVisibility(View.GONE);


在数据更新操作完成后设置

listView.setVisibility(View.VISIBLE);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  listview 线程
相关文章推荐