【发布时间】:2015-03-29 11:21:50
【问题描述】:
异常建议我调用 notifyDataSetChanged(),但我已经在 onPostExecute 方法上调用了该方法,如您所见:
Constants.newsDownloaded = true;
TempStorage.downloadedNews = this.items;
this.progress.setVisibility(View.INVISIBLE);
this.downloadMore.setVisibility(View.VISIBLE);
adapter = new NewsListAdapter(context,
inflater, this.items);
if (index <= 26){
listView.setSelection(0);
} else{
listView.setSelection(TempStorage.firstAddedIndex);
}
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
如您所见,每次调用都会重新创建适配器。我只在 Nexus 5 上遇到过这个问题,在其他设备上运行完美。
这段代码有什么问题?
感谢您的帮助,伙计们!
【问题讨论】:
-
我想你可能想看看这个帖子:stackoverflow.com/questions/3132021/…
-
@peresisUser 我检查了它。但是,正如该线程的作者所建议的那样,我总是每次都调用 notifyDataSetChanged(),只是因为在 onPostExecute 中的事实意味着每次都会调用 notifyDataSetChanged() 方法......
-
请发布您的代码
-
@Shriram 代码在问题上。该代码来自我的 onPostExecute AsyncTask。
标签: java android listview exception android-asynctask