The content of the adapter has changed but ListView did not receive a notification. Make sure the co

本文解决了一个常见问题:当使用多线程更新ListView时,如何确保数据正确地从后台线程传递到UI线程并更新视图。介绍了通过缓存处理避免ListView更新时出现的问题,并给出了具体的实现步骤。

问题: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.
翻译:适配器的内容已经改变但ListView没有收到通知。确保适配器的内容不是从后台线程修改的,而是从UI线程中修改的。确保您的适配器调用notifydatasetchanged()当其含量的变化。
解决办法
在用到多线程的时候,可以对数据做缓存处理, 比如与ListView绑定的数据存储在ArrayList (dataList), 在线程中先将数据加入到临时ArrayList(tmpList) , 最后在调用notifyDataSetChanged()方法通知UI更新之前, 把临时ArrayList(tmpList)中的数据更新到ArrayList(dataList)中, 然后清空临时ArrayList(tmpList)数据。

http://blog.youkuaiyun.com/garybook/article/details/7498342

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值