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. mysql-5.5.46源码编译安装

    1.安装准备 cat /etc/redhat-release uname -r yum install ncurses-devel cmake automake autoconf make gcc g ...

  2. STM32调试大法 之 串口通讯

    开发过程经常需要查看某些特定参数.通常的方法可以使用paintf进行打印输出,观察具体的变量值.STM32内部集成有USART的串口功能,可以通过串口直接输出到电脑(上位机).使用非常方便,基本不需要 ...

  3. Java从入门到精通——基础篇之Servlet与JSP的区别

    一.基本概念 1.1 Servlet Servlet是一种服务器端的Java应用程序,具有独立于平台和协议的特性,可以生成动态的Web页面.它担当客户请求(Web浏览器或其他HTTP客户程序)与服务器 ...

  4. 仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表中的标识列指定显式值

    今天在处理数据时遇到这样一个错误 消息 8101,级别 16,状态 1,第 1 行 仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'dbo.StockDetailValu ...

  5. 日志文件切割服务logrotate配置及crontab定时任务的使用

    1.下载logrotate 在Fedora和CentOS安装 yum install logrotate crontabs Debian和Ubuntu上 apt-get install logrota ...

  6. 如何在64位的Windows中安裝PLSQLDEVELOPER 8

    先到 Oracle 官網下載Oracle Database 11g Release 2 Client (11.2.0.1.0) for Microsoft Windows (x64) ,接者依照以下步 ...

  7. 面试问到:JDBC、hibernate、ibati

    一.JDBC.Connection(连接) 优点:运行高效.快捷. 缺点:代码多.异常多.不支持跨平台. 二.ibatis 1.根据jdbc的基本建立连接. 2.通过anntation+xml.jav ...

  8. Codeforces Round #355 (Div. 2) D. Vanya and Treasure dp+分块

    题目链接: http://codeforces.com/contest/677/problem/D 题意: 让你求最短的从start->...->1->...->2->. ...

  9. SVN--下载、安装VisualSVN server 服务端和 TortoiseSVN客户端

    前言: 在http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html的博客中已经很详细地介绍了SVN的服务器--VisualS ...

  10. 剑指offer--面试题16

    #include<stack> //思路:遍历链表过程中,将各个指针入栈,再出栈进行反转 ListNode* ReverseList(ListNode* pHead) { if(pHead ...