The content of the adapter has changed but ListView did not receive a notification,
2015-09-14 18:01
435 查看
看了下源代码ListView.java里面
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. Make sure your adapter calls notifyDataSetChanged() "
+ "when its content changes. [in ListView(" + getId() + ", " + getClass()
+ ") with Adapter(" + mAdapter.getClass() + ")]");
}
Adapter有更新没告诉listview。
我原来的代码,
new AsyncTask(){
@Override
protected Object doInBackground(Object[] objects) {
mList = getImageList();
return null;
}
@Override
protected void onPostExecute(Object result) {
mListAdapter.notifyDataSetChanged();
}
}.execute();
改为
new AsyncTask<Object, Object, List<Data>>(){
@Override
protected List<Data> doInBackground(Object[] objects) {
List<Data> result = getImageList();
return result;
}
@Override
protected void onPostExecute(List<Data> result) {
mList = result;
mListAdapter.notifyDataSetChanged();
}
}.execute();
Adapter更新跟notifyDataSetChanged都在ui线程了。
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. Make sure your adapter calls notifyDataSetChanged() "
+ "when its content changes. [in ListView(" + getId() + ", " + getClass()
+ ") with Adapter(" + mAdapter.getClass() + ")]");
}
Adapter有更新没告诉listview。
我原来的代码,
new AsyncTask(){
@Override
protected Object doInBackground(Object[] objects) {
mList = getImageList();
return null;
}
@Override
protected void onPostExecute(Object result) {
mListAdapter.notifyDataSetChanged();
}
}.execute();
改为
new AsyncTask<Object, Object, List<Data>>(){
@Override
protected List<Data> doInBackground(Object[] objects) {
List<Data> result = getImageList();
return result;
}
@Override
protected void onPostExecute(List<Data> result) {
mList = result;
mListAdapter.notifyDataSetChanged();
}
}.execute();
Adapter更新跟notifyDataSetChanged都在ui线程了。
相关文章推荐
- Android.mk--编译Android的模块
- 编译器发展及其相关介绍
- POJ3602解题报告
- Android使用fragment底部菜单栏
- C#_Winfrom下的中英文翻译
- ios开发日记- 5 屏幕截图
- 线性表【项目4 线性表-- 顺序表应用】之二
- Android:使用AsyncTask实现天气预报功能
- 纯线性同余随机数生成器
- Ajax跨域
- Nginx服务安装配置
- 智能终端双处理器架构
- LNMP系列——twemproxy缓存代理在memcached 缓存环境应用
- 实现图片轮流滑动
- Unicode、UTF8、GB2312、ANSI关系
- 程序中可能有三种类型的错误。
- 截屏
- java发邮件源码
- C语言中函数参数入栈的顺序
- C#_备份sqlserver数据库