listview提示The content of the adapter has changed but ListView did not receive a notification

listview在適配數據時,滾動listview的時候會報錯java.lang.IllegalStateException: 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 thread, but only from the UI thread. [in ListView(2131230914, class android.widget.ListView) with Adapter(class android.widget.HeaderViewListAdapter)]


經研究是adapter在handler裏面多次創建對象導致,解決方法:

1、在handler裏面判斷adapter,如果爲null,創建一次,之後就不再創建

2、在oncreate裏面創建adapter,並適配給listview,數據爲0,在handler裏面只是notifyDataSetChanged()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章