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

原因:没有在主线程里通知。。。。

1、bug 出现的地方 listView.class 1487行
if (mItemCount == 0) {
                resetList();
                invokeOnItemScrollListener();
                return;
            } else if (mItemCount != mAdapter.getCount()) {
                throw new 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(" + getId() + ", " + getClass() 
                        + ") with Adapter(" + mAdapter.getClass() + ")]");
            }
 
 
2、mItemCount != mAdapter.getCount()?
AdapterView.class  172行 
    @ViewDebug.ExportedProperty
    int mItemCount;//应该是上一次加载的数量,私有
 
3、AdapterView.class ?
ListView extends AbsListView
AbsListView extends AdapterView<ListAdapter>
 
4、网上主要解决方式
mAffairList.setVisibility(View.GONE);
mAdapter.notifyDataSetChanged();
mAffairList.setVisibility(View.VISIBLE);
 
只能解决主动通知时的情况,大多数情况是没有通知造成的
 
5、mAdapter.notifyDataSetChanged()  在做什么事?
点进去
class BaseAdapter
 public void notifyDataSetChanged() {
        mDataSetObservable.notifyChanged() ;
    }
点进去
class DataSetObservable
 public void notifyChanged() {
        synchronized(mObservers) {
            for (DataSetObserver observer : mObservers) {
                observer.onChanged();
            }
        }
    }
 
 点进去
abstract class DataSetObserver
public void onChanged() {
        // Do nothing
    }
 
AdapterView.class中
class AdapterDataSetObserver extends DataSetObserver {
 
        private Parcelable mInstanceState = null;
        @Override
        public void onChanged() { //实现方法
            mDataChanged = true;
            mOldItemCount = mItemCount;
            mItemCount = getAdapter().getCount();//关键地方
   ... ...
 
6、理论上的解决方式
listView所加载的list是静态的,大小不会变
只要list的size()变化了,就马上发通知
 
7、我的建议
只要list的size()变化了,就马上发通知
对主list的size()的改变与通知更新会存在时间差,滚动listView时不改变主list大小会大大减少bug产生,或者尽量减少动画

Android 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. android The content of the adapter has changed but ListView did not receive a notification 错误的解决方案

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

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

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

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

    使用ListView时遇到如下的异常信息: 10-26 18:30:45.085: E/AndroidRuntime(7323): java.lang.IllegalStateException: T ...

  5. 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 ...

  6. 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 ...

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

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

  8. 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 ...

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

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

随机推荐

  1. 第25章 项目6:使用CGI进行远程编辑

    初次实现 25-1 simple_edit.cgi --简单的网页编辑器 #!D:\Program Files\python27\python.exeimport cgiform = cgi.Fiel ...

  2. python操作mysql之pymysql

    pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x而后者不支持3.x版本. 本文测试python版本:2.7.11.mys ...

  3. quartus ii 中文注释乱码解决办法

    转载自:http://bbs.ednchina.com/BLOG_ARTICLE_3027549.HTM 有些时候我们用Quartus ii 打开不同版本创建的工程文件时,往往会出现下列提示 点yes ...

  4. Log4j配置和简单使用

    Log4j是一款基于Java的开源日志组件,Log4j功能非常强大,我们可以将日志信息输出到控制台.文件.用户界面,也可以输出到操作系统的事件记录器和一些系统常驻进程.更值得一提的是,Log4j可以允 ...

  5. (转)assert()函数用法总结

    assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义: #include <assert.h>void assert( in ...

  6. OpenCV+QT开发环境(一):Windows环境

    最近在学习openCV的开发.在搭建开发环境的时候,着实废了不少功夫,找了大量的文章资料.其实主要的开发还是在linux系统上的openCV,但是为了方便,我还是在windows上也搭建了开发环境,这 ...

  7. 在eclipse里的 flex 没有可视化的编辑

      注:在4.7版本里去掉了可视化编辑器.   转自:http://3470973.blog.51cto.com/3460973/1135328 最近eclipse切换了一个工作空间,创建的flex项 ...

  8. CentOS 大量的TIME_WAIT解决方法

    CentOS 大量的TIME_WAIT解决方法 最近个人博客总是出现无法打开的现象,具体表现为,打开页面需要等待n长时间,登陆系统后发现系统存在大量TIME_WAIT状态的连接,google了一下解决 ...

  9. 【UVA】【11427】玩纸牌

    数学期望 也是刘汝佳老师白书上的例题……感觉思路很神奇啊 //UVA 11427 #include<cmath> #include<cstdio> #include<cs ...

  10. MemSQL Start[c]UP 2.0 - Round 1

    A. Eevee http://codeforces.com/contest/452/problem/A 字符串水题 #include<cstdio> #include<cstrin ...