Android - IllegalStateException ListView

Android - IllegalStateException  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. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(2131427376, class android.widget.ListView) with Adapter(class adap.XXXXXXAdapter)]

找不到是哪個Activity的ListView造成的,但幸好後面有個Adapter(class adap.XXXXXAdapter)

有這個線索,就知道要去改哪一個Activity,覺得許多Adapter,還是要自定一個adapter,不然用原生的,都不知道哪個Activity會造成問題。

 

這問題已經解過很多次了,但還是發生了,

明明在同一個handler處理,但偏偏時間上的差距,也可能造成影響,或明明全都是在UI Thread,但不同的交錯(一邊按了click,另一個又開始讀網路資料)

在不同步的情況下也可以造成這個問題。

由於adapter與被動到的資料ArrayList,放在不同的地方(因為老舊程式的關係,Array是自己控制也沒用adapter原本的去控制),導致常常發生此類的問題。

網路有文章講的不錯

http://www.cnblogs.com/monodin/p/3874147.html

看完後,會瞭解很多,應該是ArrayList有任何的異動,立即呼叫Adapter.notifyDataSetChanged

所以就這樣去改。