ListView/Adapter IllegalStateException

来源:互联网 发布:淘宝海关拍卖车 编辑:程序博客网 时间:2024/05/16 07:52

今天遇到这个问题: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.

是不是你在用 adapter.notifyDataSetChanged() 刷新listview的时候,如果当前listview还未来得及刷新,你就去触摸listview,就会导致跳出出错信息呢?

 

解决办法是,通过设置listview.setVisibility(View.VISIBLE/View.GONE)。

在 adapter.notifyDataSetChanged() 之前调用listview.setVisibility(View.GONE);在adapter.notifyDataSetChanged() 之后调用listview.setVisibility(View.VISIBLE)


我个人觉得是因为数据变化了,你确没有通知listview更新,因此错误。

下面是找到的两个网址,大家可以参考。

http://stackoverflow.com/questions/3132021/android-listview-illegalstateexception-the-content-of-the-adapter-has-changed

http://www.eoeandroid.com/thread-22292-1-1.html





原创粉丝点击