读书人

小弟我重写了进度对话框listview加载

发布时间: 2012-12-14 10:33:07 作者: rapoo

我重写了进度对话框,listview加载数据的时候报这种错误,大师们你们何解?
11-21 02:19:01.997: ERROR/AndroidRuntime(733):

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(2131361816, class android.widget.ListView) with Adapter(class android.widget.HeaderViewListAdapter)]

11-21 02:19:01.997: ERROR/AndroidRuntime(733):

at android.widget.ListView.layoutChildren(ListView.java:1492)


但是我在加载成功的时候,已经写了exadapter.notifyDataSetChanged(),偶尔会报这种错误!
[最优解释]
线程1更新了Adapter中的内容,却还没有来得及通知内容已经更新,就又有线程2更新了Adapter中的内容,这个时候如果线程1再通知内容更新,就会出现上述异常了
[其他解释]
不要在新开线程调用adapter,要在UI线程调用
[其他解释]
确保更新操作是在主线程里面执行,而需要更新的数据加载可以在子线程里面
[其他解释]

引用:
线程1更新了Adapter中的内容,却还没有来得及通知内容已经更新,就又有线程2更新了Adapter中的内容,这个时候如果线程1再通知内容更新,就会出现上述异常了



我只有一个线程啊!

读书人网 >Android

热点推荐