Android The content of the adapter has changed but ListView did not receive a notification终极解决方法
这几天做一个自动扫描SD卡上所有APK文件的小工具,扫描过程中会把APK添加到LISTVIEW中显示,结果出现以下错误:(有时候触摸更新数据时候,触摸listview也会报错)
- E/AndroidRuntime(): 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(, class android.widget.ListView) with Adapter(class com.souapp.appmanager.ApkListAdapter)]
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本来就是线程不安全的,这个不关心了,看了国外一个开发者的方法很简单:
- ListView.requestLayout();
- Adatper.notifyDataSetChanged();
在你adpater更新前,调用listview的requestLayout(),这样做无非就是拟补数据数量不一致导致报错,虽然一个解决的好办法。
但是实际上用的时候我发现也会出问题,想了想最彻底的解决办法:
把 listview的adapter数据更新和dapter.notifyDataSetChanged()必须同时放到单独一个线程里,报错基本是都是这个原因,有人把adapter里的数据更新了,但是 dapter.notifyDataSetChanged() 放到一个单独线程去更新,结果出现notifyDataSetChanged更新同步的问题
题外话:解决问题还是从本质上思考,从错误信息上提示,一定避免多线程去更新adapter的数据,为此我把多线程递归遍历SD卡目录修改成了单线程;
有的时候看到别人的一些补救方法未真正解决问题。
Android 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时遇到如下的异常信息: 10-26 18:30:45.085: E/AndroidRuntime(7323): java.lang.IllegalStateException: T ...
- 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 ...
- android The content of the adapter has changed but ListView did not receive a notification 错误的解决方案
使用了AsyncTask在后台刷新适配器,并且通知ui线程更新ListView,运行时发现时不时的出现 如题 的错误, 导致程序崩溃,解决方法如下: 1.建立一个缓冲数据集,这个数据集就是填充适配器的 ...
- Android开发-- The content of the adapter has changed but ListView did not receive a notification - With AsyncTask
最近在联系开发DaysMatter时遇到一个问题: app中使用ListView来展示所有事件,每次添加完事件后使用下面代码来更新ListView. toDoListView.refreshDrawa ...
- 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 ...
- 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 ...
- 问题解决:The content of the adapter has changed but ListView did not receive a notification
1. 不要在后台线程中直接调用adapter 2. 不要在后台线程中修改adapter绑定的数据 如果对adapter或者adapter绑定的数据是在线程中,加上runOnUiThread就可以了 r ...
- 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 ...
- 【转】解决java.lang.IllegalStateException: The content of the adapter has changed but ListView...的问题
原文网址:http://blog.csdn.net/ueryueryuery/article/details/20607845 我写了一个Dialog,Dialog中有一个ListView,想要点Li ...
随机推荐
- 笨办法学 Python (第三版)(转载)
笨办法学 Python (第三版) 原文地址:http://blog.sina.com.cn/s/blog_72b8298001019xg8.html 摘自https://learn-python ...
- AIR串口通信
最近公司的项目中需要用到串口通信,项目是用基于AIR的,AIR本身是不支持串口通信的,本想用 c#或java另写一个负责串口通信的模块,又感觉很烦不想那么弄,就想到了ANE.可惜以前也没弄过 ANE, ...
- .NET开发之窗体间的传值转化操作
DOTNET开发之窗体间的传值转化操作 好想把自己最近学到的知识写下来和各位朋友分享,也希望得到大神的指点.今天终于知道自己要写点什么,就是关于WPF开发时简单的界面传值与简单操作. 涉及两个界面:一 ...
- opencv学习笔记(05)——操作相邻区域
下面的例子以灰度图像为例: #include <opencv2\highgui\highgui.hpp> #include <opencv2\imgproc\imgproc.hpp& ...
- LINQ.CS
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Zdso ...
- java_Thread生产者与消费者 Demo
package com.bjsxt.Thread.Demo; public class ProducerConsumer { /** * 生产者与消费者 * @param args */ public ...
- mysql笔记整理
删除整个表 TRUNCATE TABLE 表名; 持久链接 自动提交
- EF中使用Select new 方法中字段值替换的问题
前提需要替换查询得到的List当中的某个字段的值,替换规则有一个mapping关系 尝试代码 有问题 无法获取任何数据 /// <summary> /// 获取Treegrid的List ...
- 按键消抖VERILOG实现
对于消抖,有很多种写法.今天分享一下我的写法. 基本思路: 1. 看图 图1 ...
- 微软职位内部推荐-Senior Software Development Engineer
微软近期Open的职位: Job posting title: Senior Software Development Engineer Location: China, Beijing Divisi ...