The content of the adapter has changed but ListView did not receive a notification.
来源:互联网 发布:奥美电子 知乎 编辑:程序博客网 时间:2024/06/05 15:15
上次总结了notifyDataSetChanged()方法的注意事项,这里再补充一下该问题的解决方案:
如果在非UI线程中修改了ListView绑定的数据对象,同样会造成在非UI线程中更新主线程控件错误。
所以可以添加临时对象,在子线程中先把数据存入临时对象中,然后在通过handler处理。
在Thread中,tmpNewsData.add(hashMap);//跟mNewsData一样,先new出对象
然后通知handler处理:
Message m = new Message();
m.what = CHANGE_UI;
m.obj = tmpNewsData;
handler.sendMessage(m);
然后在主线程中进行数据的更新与界面的更新:
private Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case CHANGE_UI:
mNewsData.addAll((List<HashMap<String, Object>>) msg.obj);//千万不能能“=”赋值给mNewsData 否则notifyDataSetChanged()无效
mNewsListAdapter.notifyDataSetChanged();
break;
这样就能解决这个问题了
0 0
- listview提示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 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.
- The content of the adapter has changed but ListView did not receive a notification
- 解决bug: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
- 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
- .解决bug: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终极解决方法
- 处理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错误分析
- 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异常
- 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
- The content of the adapter has changed but ListView did not receive a notification.
- sqlmap使用笔记
- 客户端抓包的实现
- 【H5学习】浏览器对CSS属性的支持
- HDU 1047 Integer Inquiry
- Java NIO原理图文分析及代码实现
- The content of the adapter has changed but ListView did not receive a notification.
- 蓝桥杯 代码填空 组合数 递归
- (2.1.9)java的clone和浅复制克隆、深复制克隆
- hadoop2学习笔记(一)-虚拟机环境搭建
- 高数
- Java基础--网络编程
- 如何获取手机内存视频(图片)略缩图
- 异常 org.jetbrains.android.uipreview.RenderingException
- 李开复老师的算法的力量