【发布时间】:2012-10-26 20:37:47
【问题描述】:
我将commonsguy / cwac-endless EndlessAdapter 集成到我的一个应用程序中,效果非常好!感谢 CommonsWare 先生 :)
但我收到的是java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification。
注意: 这个异常只发生在我使用endlessAdapter.setRunInBackground(false);时,基本上是当我想要我自己的AsyncTask实现来缓存数据时(在cacheInBackground()方法中执行AsyncTask EndlessAdapter 类)。
重新创建此 IllegalStateException 的步骤:
步骤 1) 运行 EndlessAdapterCustomTaskFragment example 为 EndlessAdapter 提供的演示版
第 2 步)向下滚动 ListView,以便看到进度视图。
步骤 3) 单击进度视图。现在,一旦在加载数据时单击进度视图,应用程序将通过java.lang.IllegalStateException 强制关闭。
为了克服这个问题,我重写了EndlessAdapter 类的以下方法,它确实有效;)
@Override
public boolean areAllItemsEnabled() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEnabled(int position) {
// TODO Auto-generated method stub
return getItem(position) != null;
}
我很想知道以下内容:
1) 为什么EndlessAdapter 实现仅在我希望我自己的AsyncTask 实现来缓存数据时抛出异常,即endlessAdapter.setRunInBackground(false); 但在使用endlessAdapter.setRunInBackground(true); 而没有AsyncTask 的自定义实现时不会抛出异常
2) 点击ListView item 和ListView 的getCount() 方法之间有一定的关系,因为它只有在点击ListView 的进度指示器item 时才会产生Exception。
提前致谢:)
【问题讨论】:
标签: android android-listview listadapter commonsware-cwac