java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receiv

在listview刷新数据的时候出现了以下的错误问题:

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显示了。

如果您有其他更好的解决办法的话,欢迎留言!!谢谢!!



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值