java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receiv
2015-06-12 11:14
363 查看
在listview刷新数据的时候出现了以下的错误问题:
为什么会出现这个异常呢?因为我在Handler中处理的时候直接就调用了adapter.notifyDataSetChanged(),提示我要在主线程更新。
我是这样处理的:
如果您有其他更好的解决办法的话,欢迎留言!!谢谢!!
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(2131361851, class android.widget.ListView) with Adapter(class com.adth.adthtv.adapter.Box_name_adapter)]
为什么会出现这个异常呢?因为我在Handler中处理的时候直接就调用了adapter.notifyDataSetChanged(),提示我要在主线程更新。
我是这样处理的:
public class Box_name_adapter extends BaseAdapter { private Context context; private ArrayList<Map<String, Object>> list = null; private LayoutInflater inflater = null; public Box_name_adapter(Context context,ArrayList<Map<String, Object>> list){ this.context = context; this.list = list; this.inflater = LayoutInflater.from(context); selectItem = 0; } @SuppressWarnings("unchecked") public void setBoxList(ArrayList<Map<String, Object>> list1) { if (list1 != null) { list = (ArrayList<Map<String, Object>>) list1.clone(); notifyDataSetChanged(); } } public void clearBoxList() { if (list != null) { list.clear(); } notifyDataSetChanged(); } ...... }这里写了一个setBoxList(ArrayList<Map<String,Object>> list),里面的list数据发生改变时,就会调用notifyDataSetChanged(),刷新listview显示啦!clearBoxList(),当数据清空时刷新listview显示了。
如果您有其他更好的解决办法的话,欢迎留言!!谢谢!!
相关文章推荐
- java如何得到GET和POST请求URL和参数列表
- java中的方法重载和方法覆盖
- Java调用QQ快速聊天-调用CMD命令打开网址
- java 安装数据库驱动
- Ubuntu 14.04 安装 JDK 8
- [Spring]04_最小化Spring XML配置
- Eclipse常用快捷键记录
- Java环境配置
- Eclipse将引用了第三方jar包的Java项目打包成jar文件的两种方法
- Java中Integer的最大值和最小值
- java FTP上传文件(进度条显示进度)
- 利用Spring自定义AOP进行Session超时自动跳转到登录页面
- java中的单例设计模式
- Java thread jargon
- Spring3.2.1+Hibernate4.1.7 多数据源动态切换
- JAVA 计算字符串的高度和宽度
- 在Spring3中使用注解(@Scheduled)创建计划任务
- 新版eclipse和命令行不能同时连接调试设备
- Java打开本地文件/exe/打开网址/调用cmd
- java贪吃蛇游戏一