1. 程式人生 > >The content of the adapter has changed but ListView did not receive a notification的解決方案

The content of the adapter has changed but ListView did not receive a notification的解決方案

開發過程中,使用ListView時,發現這個錯誤偶爾會出現。特別是做壓力測試的時候,不停的點選重新整理,更容易出現這個錯誤。

在網上找了一下關於這個問題的解決辦法,說的是直接備份一份資料來源,我根據他們說的,辦法是可行的,上程式碼。

public void setDataList(ArrayList<Map<String, Object>> dataList) {
    if (dataList != null) {
        mDatas = (List<Map<String, Object>>) dataList.clone();
        notifyDataSetChanged();
    }
}

public void 
clearDataList() { if (mDatas != null) { mDatas.clear(); } }
if (mNotificationAdapter == null) {
    mNotificationAdapter = new AdpFragNotificationList(mActivity);
    mNotiSwipeView.setAdapter(mNotificationAdapter);
}
mNotificationAdapter.setDataList(mNotiList);

在重新整理的時候,呼叫setDataList()方法,這只是一種迂迴的方法,後來發現本質的原因,還是因為在重新整理介面卡的時候,呼叫介面之前,清空了資料來源的內容,然後再填充介面卡,導致的資料來源與介面卡不匹配。上程式碼。
mPromotionSwipeView
.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mPromotionList.clear(); getDataList(false, 0); } });
只需要將資料來源中的清除放到更新介面卡前清除即可。

相關推薦

IllegalStateException:content of the adapter has changed but ListView did not receive a notification

java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the

The content of the adapter has changed but ListView did not receive a notification解決方案

在開發過程中,使用ListView時,發現這個錯誤偶爾會出現。特別是做壓力測試的時候,不停的點選重新整理,更容易出現這個錯誤。 在網上找了一下關於這個問題的解決辦法,說的是直接備份一份資料來源,我根據

解決ListViewThe content of the adapter has changed but ListView did not receive a notification崩潰問題

最近在寫一個聚合工具箱的時候,添加了滑動返回功能,使用ListView時(不要問我為啥不用recycleview,小工具嘛,主要是邏輯,頁面都是次要的),遇到如下崩潰問題 java.lang.IllegalStateException: The content of t

ListView資料來源不同步問題The content of the adapter has changed but ListView did not receive a notification.

最近專案中出現了很多下面的異常: java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Mak

非同步載入Listview The content of the adapter has changed but ListView did not receive a notification

錯誤 The content of the adapter has changed but ListView did not receive a notification 原因 在Android開發過程中,使用了大量的ListView,發現這個錯誤偶爾會出現。特別是做壓力測

Listview更新資料時崩潰The content of the adapter has changed but did not receive a notification.

說明:在工作中遇到的問題記錄下來,歡迎批評和指正~ 1、問題 在listView上下拉重新整理或者滑動過程中經常碰到這個復現率比較高的崩潰問題 E/AndroidRuntime(16779): j

Adapter報錯:The content of the adapter has changed解決

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

(轉)關於AdapterThe content of the adapter has changed問題分析

1 07-28 17:22:02.162: E/AndroidRuntime(16779): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a no

解決The content of element type "web-app" must match "(icon?display

內容 param match filter res ros welcome local page http://www.educity.cn/wenda/126463.html 解決:The content of element type "web-app" must ma

web.xml中<web-app>提示The content of element type "web-app" must match "(icon?,display- name?,description?,distributable?,

session span text .com ble splay 錯誤 esc gin 錯誤:配置web.xml時,出現紅色叉叉,提示 The content of element type "web-app" must match "(icon?,display-

strus2配置strus.xml問題-The content of element type "package" must match "(result-types?,interceptors?

ngs ppi 需要 ML 問題 所有 -i app exc 搭建strus2項目,在配置strus.xml時候碰到了這個問題: The content of element type "package" must match "(result-types?,interce

寫hibernate.cfg.xml時報錯The content of element type "property" must match "(meta*,(column|formula)*,type?)".

原配置檔案是這樣的 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "htt

web.xml中 web-app 報錯了--The content of element type "web-app" must match

web.xml中<web-app>報錯了--The content of element type "web-app" must match。真是活見鬼! 查完資料後發現,原來web-app_2_3.dtd規範有規定,裡面配置的內容要按照規定的順序來,如下:

An engine that classifies the content of a Reddit post: an application of Natural Language…

An engine that classifies the content of a Reddit post: an application of Natural Language Processing“white text on black background” by Lauren Peng on Uns

Richard Liu, the CEO of JD.com, has been Accused of Rape

Richard Liu’s conduct is under investigation as Chinese netziens are in an uproar.Richard Liu, the CEO of JD.com, has been Accused of RapeThat time China a

The content of element type "web-app" must match "

報錯資訊: The content of element type "web-app" must match "(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,list

The content of element type "package" must match 。。。。。。

今天寫東東的時候,在struts。xml中的 配置預設action的時候,總是有錯,報異常如下: Caused by: The content of element type "package" must match "(result-types?,interceptors?,default-i

The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collect

The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collect   轉載:https://blog.csdn.net/chenxing1990/ar

The content of element type "struts" must match "((package|include|bean|constant)*,unknown-handler-s

錯誤資訊     The content of element type "struts" must match "((package|include|bean|constant)*,unknown-handler-stack?)". 我在做Spr

The content of element type "package" must match "(result-types?,interceptors?,default-interceptor-r

struts.xml檔案報瞭如下錯誤 Multiple annotations found at this line:     - The content of element type "package" must match "(result-types?,