使用ListView时遇到如下的异常信息:

10-26 18:30:45.085: E/AndroidRuntime(7323): 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. [in ListView(2131296280, class android.widget.ListView) with Adapter(class com.souapp.appmanager.ApkListAdapter)]

其实我在listview的adapter添加完数据后,使用了handler去调用datper.notifyDataSetChanged();来通知listview显示变化结果;

虽然自己很确定没有多线程操作,但是有人说listview本来就是线程不安全的,这个不关心了,看了国外一个开发者的方法很简单。

解决方法1:

ListView.requestLayout();  

Adatper.notifyDataSetChanged(); 

在你adpater更新前,调用listview的requestLayout(),这样做无非就是弥补数据数量不一致导致报错,虽然一个解决的好办法。

但是实际上用的时候我发现也会出问题,想了想最彻底的解决办法

彻底解决方法:

把  listview的adapter数据更新和dapter.notifyDataSetChanged()方法的调用必须同时放到单独一个线程里,报错基本是都是这个原因,有人把adapter里的数据更新了,但是 dapter.notifyDataSetChanged() 放到一个单独线程去更新,结果出现notifyDataSetChanged更新同步的问题

以上内容来自:http://blog.csdn.net/changemyself/article/details/8116670

解决更新ListView数据时出现的问题分析总结:

  没仔细读的话,一眼看去就说说在非UI线程去更新了ListVIew的数据,然后下意识的认为是调用adapter.notifyDataSetChanged方法的调用被放到了非UI线程,仔细一看是说更新ListView的数据以及通知数据更新要放到同一个线程(主线程),是为了保持数据一致,adapter里面一般是会存放一个数组,对那个数据的修改和调用notifyDataSetChanged方法要放到一起,而且是放到主线程,如果对数据的更新放到了子线程,notifyDataSetChanged的调用在主线程,notifyDataSetChanged的调用会默认把ListView绑定到主线程里面了,这个时候子线程来更新数据的话就会出现在非UI线程修改UI线程的东西了。

这个问题也不是必崩溃,低版本崩的多,高版本好像崩溃得少

ListView:The content of the adapter has changed but ListView did not receive a notification终极解决方法的更多相关文章

  1. Android The content of the adapter has changed but ListView did not receive a notification终极解决方法

    这几天做一个自动扫描SD卡上所有APK文件的小工具,扫描过程中会把APK添加到LISTVIEW中显示,结果出现以下错误:(有时候触摸更新数据时候,触摸listview也会报错) E/AndroidRu ...

  2. The content of the adapter has changed but ListView did not receive a notification

    java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive ...

  3. Android 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. Make sure the co ...

  4. 【转】解决java.lang.IllegalStateException: The content of the adapter has changed but ListView...的问题

    原文网址:http://blog.csdn.net/ueryueryuery/article/details/20607845 我写了一个Dialog,Dialog中有一个ListView,想要点Li ...

  5. Android开发-- The content of the adapter has changed but ListView did not receive a notification - With AsyncTask

    最近在联系开发DaysMatter时遇到一个问题: app中使用ListView来展示所有事件,每次添加完事件后使用下面代码来更新ListView. toDoListView.refreshDrawa ...

  6. android The content of the adapter has changed but ListView did not receive a notification 错误的解决方案

    使用了AsyncTask在后台刷新适配器,并且通知ui线程更新ListView,运行时发现时不时的出现 如题 的错误, 导致程序崩溃,解决方法如下: 1.建立一个缓冲数据集,这个数据集就是填充适配器的 ...

  7. java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification

    ListView UI重绘时触发layoutChildren, 此时会校验listView的mItemCount与其Adapter.getCount是否相同,不同报错. ListView.layout ...

  8. 问题解决:The content of the adapter has changed but ListView did not receive a notification

    1. 不要在后台线程中直接调用adapter 2. 不要在后台线程中修改adapter绑定的数据 如果对adapter或者adapter绑定的数据是在线程中,加上runOnUiThread就可以了 r ...

  9. 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. Make s

    我出现这个问题是引用资源文件问题 helper.getView(R.id.in_pic).setBackgroundResource(item.getResourceId()); //错的helper ...

随机推荐

  1. OSD磁盘日常监控

    摘要:对ceph OSD磁盘,做好定期的性能数据采集和通电时长管理,长期的数据积累对磁盘的性能与生命周期管理会有一定帮助,同时也能确保整个集群性能的稳定. 磁盘碎片管理 查看磁盘碎片 # xfs_db ...

  2. SCRUM报告(1)

    我们组的PM是白杰,团队SCRUM 报告如下: 一.第一次spring会议内容: 1.确定所做项目的方向: 2.将调查问卷的结果进行统计,做了需求分析,大致了解了用户的想法: 3.确定了团队计划bac ...

  3. 浅谈 facebook .net sdk 应用

    今天看了一篇非常好的文章,就放在这里与大家分享一下,顺便也给自己留一份.这段时间一直在学习MVC,另外如果大家有什么好的建议或者学习的地方,也请告知一下,谢谢. 这篇主要介绍如何应用facebook ...

  4. 深入理解Ember-Data特性(上)

    写在前面 最近比较忙,换了新工作还要学习很多全新的技术栈,并给自己找了很多借口来不去坚持写博客.常常具有讽刺意味的是,更多剩下的时间并没有利用而更多的是白白浪费,也许这就是青春吧,挥霍吧,这不是我想要 ...

  5. jeechart

    个人网站地址:http://blog.niubua.com jeechart(1)——普通的分页查询 :http://blog.niubua.com/2014/09/18/jeechart(1)-普通 ...

  6. IOS Socket 05-XMPP开始&安装服务器openfire&安装配置客户端

    1. 即时通讯技术简介(IM) 即时通讯技术(IM-Instant Messageing)支持用户在线实时交谈.如果要发送一条信息,用户需要打开一个小窗口,以便让用户及其朋友在其中输入信息并让交谈双方 ...

  7. 暂停JS的深入学习

    对于JS的掌握程度,已经满足中级前端工程师的需要了,现在需要入门一下后端的基础知识,如nginx服务器一类的知识,方便今后快速开发. 先来nginx,文章.

  8. 关于redis启动流程介绍

    转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/94.html?1455870894 1. 准备运行环境 * 设置oom h ...

  9. SpringMVC与mybatis整合

    一.逆向工程生成基础信息 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generator ...

  10. javascript中this指向

    在简单函数中,this是指向当前对象,可用来获取当前对象某个属性,但随着函数变复杂,this很多情况不指向当前对象,而是指向window. 1.在独立调用函数中,具有全局执行环境,this指向wind ...