【转】关于Adapter的The content of the adapter has changed问题分析 关于Adapter的The content of the adapter has changed问题分析
原文网址:http://www.cnblogs.com/monodin/p/3874147.html
1、问题描述
1 07-28 17:22:02.162: E/AndroidRuntime(16779): 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. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(2131034604, class android.widget.ListView) with Adapter(class com.nodin.sarah.HeartListAdapter)]
2
3 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.ListView.layoutChildren(ListView.java:1555)
4
5 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.AbsListView.onLayout(AbsListView.java:2091)
6
7 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785)
8
9 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631)
10
11 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
12
13 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785)
14
15 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631)
16
17 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
18
19 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
20
21 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785)
22
23 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631)
24
25 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1589)
26
27 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785)
28
29 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631)
30
31 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
32
33 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785)
34
35 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631)
36
37 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
38
39 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
40
41 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785)
42
43 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631)
44
45 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
46
47 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
48
49 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
50
51 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785)
52
53 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631)
54
55 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
56
57 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
58
59 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785)
60
61 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631)
62
63 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1985)
64
65 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1742)
66
67 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
68
69 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5582)
70
71 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
72
73 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
74
75 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.Choreographer.doFrame(Choreographer.java:532)
76
77 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
78
79 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.os.Handler.handleCallback(Handler.java:733)
80
81 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.os.Handler.dispatchMessage(Handler.java:95)
82
83 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.os.Looper.loop(Looper.java:137)
84
85 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.app.ActivityThread.main(ActivityThread.java:4998)
86
87 07-28 17:22:02.162: E/AndroidRuntime(16779): at java.lang.reflect.Method.invokeNative(Native Method)
88
89 07-28 17:22:02.162: E/AndroidRuntime(16779): at java.lang.reflect.Method.invoke(Method.java:515)
90
91 07-28 17:22:02.162: E/AndroidRuntime(16779): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
92
93 07-28 17:22:02.162: E/AndroidRuntime(16779): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
94
95 07-28 17:22:02.162: E/AndroidRuntime(16779): at dalvik.system.NativeStart.main(Native Method)
96
97 07-28 17:22:02.162: W/ActivityManager(588): Force finishing activity
2、复现场景
3、原因分析
1 // Handle the empty set by removing all views that are visible
2 // and calling it a day
3 if (mItemCount == 0) {
4 resetList();
5 invokeOnItemScrollListener();
6 return;
7 } else if (mItemCount != mAdapter.getCount()) {
8 throw new IllegalStateException("The content of the adapter has changed but "
9 + "ListView did not receive a notification. Make sure the content of "
10 + "your adapter is not modified from a background thread, but only "
11 + "from the UI thread. [in ListView(" + getId() + ", " + getClass()
12 + ") with Adapter(" + mAdapter.getClass() + ")]");
13 }
4、解决方案
- 确保Adapter的数据更新后一定要调用notifyDataSetChanged()方法通知ListView
- 数据更新和notifyDataSetChanged()放在UI线程内,且必须同步顺序执行,不可异步
- 仔细检查确认getCount()方法返回值是否正确
【转】关于Adapter的The content of the adapter has changed问题分析 关于Adapter的The content of the adapter has changed问题分析的更多相关文章
- I have Flash Player installed, but I am unable to view Flash content in Chromium. How do I enable Flash Player to view this content?
I have Flash Player installed, but I am unable to view Flash content in Chromium. How do I enable Fl ...
- 包含了重复的“Content”项。.NET SDK 默认包含你项目目录中的“Content”项。可从项目文件中删除这些项;如果希望将其显式包含在项目文件中,可将“EnableDefaultContentItems”属性设置为“false”
从.netcore 1.1 升级到2.0时遇到该问题. 参考http://www.cnblogs.com/xishuai/p/visual-studio-for-mac.html 根据提示可知(我是看 ...
- Android开发-API指南-创建 Content Provider
Creating a Content Provider 英文原文:http://developer.android.com/guide/topics/providers/content-provide ...
- Android开发-API指南-Content Provider基础
Content Provider Basics 英文原文:http://developer.android.com/guide/topics/providers/content-provider-ba ...
- Android中的Adapter 详解
http://blog.csdn.net/tianfeng701/article/details/7557819 (一) Adapter介绍 Android是完全遵循MVC模式设计的框架,Activi ...
- Content Provider Basics ——Content Provider基础
A content provider manages access to a central repository of data. A provider is part of an Android ...
- Dhroid框架笔记(DhNet、Adapter)
3.1.1 DhNet用于获取网络中的数据 DhNet net=new DhNet("路劲"); net.addParam("key", "参数&qu ...
- Android应用程序组件Content Provider应用实例
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6950440 文简要介绍了Android应用程序 ...
- android-适配Adapter
Adapter是把数据和用户界面视图绑定到一起的桥梁类,负责创建用来表示父视图中的每一个条目的子视图,并提供对底层数据的访问. public class MainActivity extends Ac ...
- 我的Android 4 学习系列之数据库和Content Provider
目录 创建数据库和使用SQLite 使用Content Provider.Cusor和Content Value来存储.共享和使用应用程序数据 使用Cursor Loader异步查询Content P ...
随机推荐
- cocos2d-x游戏开发(十七)NDK+ant编译暗黑世界
个人原创,欢迎转载http://blog.csdn.net/dawn_moon/article/details/12308967 9秒论坛的客户端暗黑世界,ios已经跑过了,今天搞了一下安卓的,记录一 ...
- JDBC编程之优化
1.创建 dbconfig.properties driver=com.mysql.jdbc.Driver dburl=jdbc\:mysql\://localhost\:3306/mytest us ...
- hdu 1253 胜利大逃亡 (三维简单bfs+剪枝)
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- VLV INDEX
Normally, when the Directory Server conducts a search, the server looks through the entire entry for ...
- mysql 的密码重置
Windows: 1.以系统管理员登陆: 2.停止MySQL服务: 3.进入CMD,进入MySQL的安装目录,假设是D:/MySQL/MySQL Server 5.0/: 4.跳过权限检查启动MySQ ...
- Win8 弹出窗口不在最前端的解决方法
Win8系统的使用者有很多会遇到弹出窗口不在最前端的情况(自动隐藏,点下页面又出来),比如另存为的时候 ,或是登录路由器时弹出的登录框时. 引起这个异常的原因是与系统输入法冲突引起,但又不可能不用第三 ...
- UML基础知识
UML:Unified Modeling Language,即统一建模语言.是一种图形化的建模语言标准. 如上图,UML可以帮助我们做软件需求分析和软件设计两方面的工作,在不同的应用场景中,UML的一 ...
- 修改Sharepoint 文档库列表点击Excel文件默认跳转到Excel Service服务 xlviewer.aspx页面
在Sharepoint 文档库中,当点击库中的一个Excel文件时,Sharepoint默认为转跳到Excel Services上,无论是Sharepoint 的是否开启了Excel Service, ...
- 深入理解REST与Servlet架构的区别
本身这个比较是个伪命题,因为 RESTful Service是一个软件架构“风格”, 而servlet是java 服务端的一种技术 之所以把它们拿出来比较,是由于它们代表了两个时代的技术风格与架构.下 ...
- string的一些操作,类似数组
1.串的切割 var a="hello world";//a.length=11 alert(a.slice(3)); alert(a.substring(3)); alert(a ...