更新适配器数据时出现IllegalStateException

时间:2017-11-28 12:21:15

标签: android listview android-studio android-adapter

请帮助我找到针对此错误的修复程序,它出现在生产版本中,我不知道错误位于以下日志中。

我从Crashlytics获得了以下日志报告:

ListView.java line 1557
android.widget.ListView.layoutChildren 

Fatal Exception: 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(2131558802, class 
android.widget.ListView) with Adapter(class 
android.widget.HeaderViewListAdapter)]
   at android.widget.ListView.layoutChildren(ListView.java:1557)
   at android.widget.AbsListView.onTouchEvent(AbsListView.java:3442)
   at android.view.View.dispatchTouchEvent(View.java:7565)
   .
   .
   .

1 个答案:

答案 0 :(得分:0)

您只能更改主线程中的数据。

如果要在后台线程中获取数据,请等待主线程中的结果,更改数据,然后调用adapter.notifyDataSetChanged(),或者使用处理程序从后台线程返回主线程。一个run()方法。

相关问题