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. Word 使用技巧

    文档的写作,例来分为latex与word两大阵营.一个是论文界的宠儿,一个是平民的所见即所得.看起来好像前者更加牛一些. 本来我也是觉得latex比word好.但是使用latex时苦于找不到一个好的编 ...

  2. C语言文件函数

    FILE *fp: 其中的FILE应该大写,它实际上是系统定义的一个结构,在stdio.h文件中.该结构中有文件名,文件状态,文件当前的读写信息等. fp是指向FILE结构的指针变量,通过fp可以找到 ...

  3. ActiveMQ之TemporaryQueue和TemporaryTopic

    TemporaryQueue和TemporaryTopic,从字面上就可以看出它们是“临时”的目的地.可以通过Session来创建,例如: TemporaryQueue replyQueue = se ...

  4. 自定义Adapter

    --MainActivity代码 package com.example.qqdemo; import java.util.ArrayList; import java.util.List; impo ...

  5. 【css老版本浏览器兼容利器】ie-css3.htc

    做前端的同学都应该听说或者用过,是一段脚本,可以让ie实现css3里的圆角和阴影效果. css带来的便利是很容易感受的到的,但恶心的是它在ie下的不兼容,所以某位牛人现身写了个ie-css3.htc, ...

  6. iOS 8安装教程图解

    苹果最新移动设备操作系统iOS 8终于在今天开放下载.相较于iOS 7,iOS 8此次最大的变化包括苹果全新的健康应用.允许用户跨设备操作的连续性(Continuity)功能等. iOS 8的整体软件 ...

  7. Very large tabs in eclipse panes on Ubuntu

    http://stackoverflow.com/questions/11805784/very-large-tabs-in-eclipse-panes-on-ubuntu ou can edit E ...

  8. Error: Most middleware (like bodyParser) ...

    运行NodeJS时出现如下错误: Error: Most middleware (like bodyParser) is no longer bundled with Express and must ...

  9. Ubuntu 查看文件以及磁盘空间大小命令df

    (1)查看文件大小 查看当前文件夹下所有文件大小(包括子文件夹)    du -sh   # du -h 15M     ./package 16K     ./.fontconfig 4.0K    ...

  10. ffmpeg 编码

    编码可以简单理解为将连续的图片帧转变成视频流的过程.以H264为例给出编码的代码: int InitEncoderCodec(int width, int height) { auto enc = a ...