即使在列表视图java.lang.IllegalStateException调用notifyDataSetCanged(); [英] list view java.lang.IllegalStateException even after calling notifyDataSetCanged();

查看:159
本文介绍了即使在列表视图java.lang.IllegalStateException调用notifyDataSetCanged();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.lang.IllegalStateException:适配器的内容发生了变化,但ListView控件没有收到通知。确保您的适配器的内容是不是从后台线程修改,但只能从UI线程。

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.

我的列表视图中包含巨大的data`s

my list-view contains huge data`s

现在用的处理程序调用波纹管code当数据列表中的更改

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

推荐答案

问题是不是哪里适配器更新,应该是:时的适配器更新

它看起来喜欢:你的数据绑定到该适配器已经被改变,并且UI都进行更新,所以这个时候,系统查找数据更改,但不能调用 notifyDataSetChanged

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.

所以,建议当您更改适配器的数据,调用 notifyDataSetChanged 立即

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

不定向改变你的线程适配器的数据,则应该将数据发送到 hanlder ,而在处理使用数据来替换或更改适配器的数据和 notifyDataSetChanged

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.

所以无论如何,建议拿到的数据可以在后台线程中运行,并更新数据, notifyDataSetChanged 在UI线程中使用。

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

这篇关于即使在列表视图java.lang.IllegalStateException调用notifyDataSetCanged();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆