相关疑难解决方法(0)

Android,ListView IllegalStateException:"适配器的内容已更改,但ListView未收到通知"

我想做什么:运行后台线程计算ListView内容并部分更新ListView,同时计算结果.

我知道我必须避免:我不能从后台线程中弄乱ListAdapter内容,所以我继承了AsyncTask并从onProgressUpdate发布结果(向适配器添加条目).我的适配器使用结果对象的ArrayList,这些arraylists上的所有操作都是同步的.

其他人的研究:有非常有价值的数据在这里.对于500名用户来说,我几乎每天都会遇到崩溃,当我list.setVisibility(GONE)/trackList.setVisibility(VISIBLE)在onProgressUpdate中添加了阻塞时,崩溃率下降了10倍但没有消失.(有人建议回答)

我有时得到的:请注意,它很少发生(每周一次为3.5k用户之一).但我想完全摆脱这个错误.这是部分堆栈跟踪:

`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(2131296334, class android.widget.ListView) with Adapter(class com.transportoid.Tracks.TrackListAdapter)]
at android.widget.ListView.layoutChildren(ListView.java:1432)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:2062)
at android.widget.ListView.onTouchEvent(ListView.java:3234)
at android.view.View.dispatchTouchEvent(View.java:3709)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
[...]
Run Code Online (Sandbox Code Playgroud)

救命?不再需要了,见下文

最终答案:事实证明,我notifyDataSetChanged每次调用5次以避免闪烁和突然更改列表.它不能这样做,总是在基本列表更改时通知适配器.这个错误现在已经消失了.

android listview exception adapter

187
推荐指数
6
解决办法
12万
查看次数

标签 统计

adapter ×1

android ×1

exception ×1

listview ×1