发现一个有时候会出现的错误:
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(2131165196, class android.widget.ListView) with Adapter(class com.jovision.multiscreen.views.DeviceScanSelectDialog$DeviceAdapter)
需要data.addAll,Adapter.notifyDataSetChanged()
在主线程执行,
data
.addAll(data_update)
;
if (data_update_size< 20){
mListView .setPullLoadEnable(false) ;
}else {
mListView .setPullLoadEnable(true) ;
}
onLoad();
if (data_update_size< 20){
mListView .setPullLoadEnable(false) ;
}else {
mListView .setPullLoadEnable(true) ;
}
onLoad();
mAlertAdapter.notifyDataSetChanged();
本文介绍了一个关于ListView在数据更新时未能正确接收通知的问题,并提供了解决方案。问题出现在尝试从后台线程修改适配器内容时,解决方案是在主线程中使用data.addAll()和notifyDataSetChanged()方法。
2057

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



