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;
}
本文介绍了一种解决Android开发中ListView出现java.lang.IllegalStateException错误的方法。通过重写notifyDataSetChanged()方法并在其中更新数据集大小,确保了数据变化时ListView能够正确接收到通知。
122

被折叠的 条评论
为什么被折叠?



