The content of the adapter has changed but ListView did not receive a notification
来源:互联网 发布:龙华数据恢复 编辑:程序博客网 时间:2024/06/08 14:47
The content of the adapter has changed but ListView did not receive a notification
在Android开发过程中,使用了大量的ListView,发现这个错误偶尔会出现。特别是做压力测试的时候,不停的点击刷新,更容易出现这个错误。代码中已经使用了Adapter的notifyDataSetChanged()方法通知UI更新了,但是还是会出现这个错误。究其根本原因,还是线程之间同步的问题。比如,线程1更新了Adapter中的内容,却还没有来得及通知内容已经更新,就又有线程2更新了Adapter中的内容,这个时候如果线程1再通知内容更新,就会出现上述异常了。
在此提出一些解决办法:
对线程进行管理,如果当前Actitivty暂停了,及时停止这些线程。
数据更新后,要及时使用notifyDataSetChanged()方法通知UI,避免出现数据不一致的情况。
数据的更新,最好放在主线程中进行。这样可以使用同步数据更新与通知内容更新部分的代码。
最后补充一条我最终解决问题的方法:
在用到多线程的时候,可以对数据做缓存处理, 比如与ListView绑定的数据存储在ArrayList (dataList), 在线程中先将数据加入到临时ArrayList(tmpList) , 最后在调用notifyDataSetChanged()方法通知UI更新之前, 把临时ArrayList(tmpList)中的数据更新到ArrayList(dataList)中, 然后清空临时ArrayList(tmpList)数据。
0 0
- listview提示The content of the adapter has changed but ListView did not receive a notification
- ListView异常:The content of the adapter has changed but ListView did not receive a notification
- ListView The content of the adapter has changed but ListView did not receive a notification.
- The content of the adapter has changed but ListView did not receive a notification.
- The content of the adapter has changed but ListView did not receive a notification
- 解决bug:The content of the adapter has changed but ListView did not receive a notification
- The content of the adapter has changed but ListView did not receive a notification
- The content of the adapter has changed but ListView did not receive a notification.
- The content of the adapter has changed but ListView did not receive a notification
- .解决bug:The content of the adapter has changed but ListView did not receive a notification .
- The content of the adapter has changed but ListView did not receive a notification终极解决方法
- 处理The content of the adapter has changed but ListView did not receive a notification异常
- The content of the adapter has changed but ListView did not receive a notification错误分析
- The content of the adapter has changed but ListView did not receive a notification 异常解析
- 处理The content of the adapter has changed but ListView did not receive a notification异常
- The content of the adapter has changed but ListView did not receive a notification终极解决方法
- The content of the adapter has changed but ListView did not receive a notification
- The content of the adapter has changed but ListView did not receive a notification.
- 去掉std::string或std::wstring的最后一个字符的简单方法
- Android 在TextView中使用AutoLink,并自定义点击链接后的行为
- ResultSet用法集锦
- java shiro、maven、Bootstrap、HTML5、SpringMVC、Mybatis、Hibernate、安全权限、高性能、高并发
- Android自定义控件(二)——圆形进度条以及回调方法
- The content of the adapter has changed but ListView did not receive a notification
- php上传文件大小限制解决方法
- JAVA连接MYSQL配置
- CSS实现自适应圆角矩阵——滑动门
- wstring,WCHAR,TCHAR,CHAR
- The superiority of the Chinese film faced plywood
- 用Eclipse 开发Dynamic Web Project应用程序
- DirectX9 初始化Direct3D通用框架
- [LeetCode] Integer to Roman