Android Monkey导致android.widget.HeaderViewListAdapter中的适配器通知异常

mpa*_*raz 5 android android-monkey

我有一个共同的问题:

java.lang.IllegalStateException: The content of the adapter has changed but List
View did not receive a notification. Make sure the content of your adapter is no
t modified from a background thread, but only from the UI thread. [in ListView(2
131427573, class android.widget.ListView) with Adapter(class android.widget.Head
erViewListAdapter)]
Run Code Online (Sandbox Code Playgroud)

但是适配器不是我的代码,而是在android.widget.HeaderViewListAdapter 使用Jellybean.

我通过对源代码的阅读HeaderViewListAdapter,ListAdapterListView.该IllegalStateException当项目在计数时,抛出ListView不等于所提供的计数ListAdapter.在这种情况下,ListAdapterHeaderViewListAdapter.该HeaderViewListAdaptercount:伯爵是原来的数ListAdapter由客户端代码中传递,再加上页眉和页脚的大小.

我追查了我的代码.所有访问ListView都在UI线程上,并始终跟随notifyDataSetChanged()适配器.我正在使用一个页脚.

在正常使用中不会发生这种情况.是猴子吗?但是Monkey如何从其他线程修改我的变量?

  • 更多Monkey测试后更新

我通过删除呼叫删除了页脚addFooterView().Monkey不再触发异常.我应该addFooterView()在某个时候取消电话吗?

Rom*_*zak 9

你可以尝试在ListView中添加这样的东西:

    @Override
protected void layoutChildren() {
    try {
        super.layoutChildren();
    } catch (IllegalStateException e) {
        ZLog.e(LOG, "This is not realy dangerous problem");
    }
}
Run Code Online (Sandbox Code Playgroud)

如果添加headerview或footerview ListView,并且当你通知notifyDataSetChanged()时,它会将mItemCount更改为真实适配器的项目数,但右侧将返回添加了headercount和footercount的虚假itemcount.

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/android/widget/ListView.java?av=f#1538