The content of the adapter has changed but ListView did not receive a notification

来源:互联网 发布:杭州淘宝拍摄 编辑:程序博客网 时间:2024/06/10 08:22

android 新手,在开发中遇到第一次见到的一个错误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. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(2131296805, class android.widget.ListView) with Adapter(class cn.lingox.android.adapter.ChatAllHistoryAdapter)],查阅了好多资料也看到了android大牛的博客等 等,说的一些解决 此问题的方式, 我采用了一种比较简单的方式

重写 notifyDataSetChanged()方法,在方法中获取集合的大小,然互在getcount 中返回集合大小即可

  @Override
    public void notifyDataSetChanged() {
        size = datas.size();

        super.notifyDataSetChanged();
    }

getcount中返回集合大小

       @Override
    public int getCount() {

//        return datas.size();
        return size;
    }



1 0