![](/img/trans.png)
[英]java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification in android Studio
[英]Android: java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification
異常建議我調用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上遇到過此問題,在其他設備上也可以正常使用。
此代碼有什么問題?
謝謝大家的幫助!
我認為您應該刪除notifyDataSetChanged行。 無論如何,您都在創建一個新的適配器實例,為什么要立即對其進行命名? 它具有正確的更新數據,因為您有一個新實例。
在更新我在適配器中查詢的數據時,我曾經在類似的情況下遇到過相同的崩潰。 通過僅在onPostExecute中創建一個新的適配器實例,我擺脫了崩潰。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.