Android Exception 6 (adapter is not modified from a background thread)

时间:2022-06-30 17:34:43

07-23 09:47:34.962: E/AndroidRuntime(7001): 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(2131230794, class com.tongyan.widget.view.PullToRefreshListView) with Adapter(class android.widget.HeaderViewListAdapter)]

这个问题出现的场景是,在同一个Activity中,既使用了Thread,并且使用了AsyncTask

网上找来的:

1.改变适配器Adapter内容时不要在后台线程中,必须在UI线程中处理,这点可以通过Handler传出来解决。

2.尝试Adapter的notifyDataSetChanged()方法,当然主要看你代码的具体情况。