list view java.lang.IllegalStateException even after calling notifyDataSetCanged();

时间秒杀一切 提交于 2019-12-04 04:55:21

问题


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.

my list-view contains huge data`s

am calling the bellow code using handler when the data is changed in the list

  listviewAdapter.notifyDataSetChanged();

but i get the same error some times and not every time i load it thanks in advance


回答1:


the question is not where the adapter update, it should be: the time the adapter update.

it look likes: your data bind to the adapter has be changed, and the ui have be updated, so this time, the system find the data changed but can't invoke the notifyDataSetChanged.

so, suggestion when you change the adapter's data, invoke notifyDataSetChanged immediately,

or

dont directed change the adapter's data in your thread, you should send the data to the hanlder, and in the handler using the data to replace or change the adapter's data and notifyDataSetChanged.

so anyway, suggestion get the data can run in background thread, and update the data , notifyDataSetChanged used in ui thread.




回答2:


the error is quite clear. You have not to call listviewAdapter.notifyDataSetChanged(); from a thread different of the UI thread.




回答3:


Modify the arguments of the adapter in runOnUIThread() or use a handler to notify the adapter that the dataset has changed.



来源:https://stackoverflow.com/questions/10241765/list-view-java-lang-illegalstateexception-even-after-calling-notifydatasetcanged

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!