天天看點

處理The content of the adapter has changed but ListView did not receive a notification異常

istview在更新時報異常:

error/androidruntime(15260): 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(2131099657, class android.widget.listview) with adapter(class com.pocketdigi.pptheater.listadapter)]

網上有很多蛋疼或者治标不治本的解決方法,其實解決方法很簡單:

1.如何你使用線程處理的背景資料,那麼就在run方法裡面用handler将資料send出來到主線程裡面的handlemessage然後再addall或者指派;

2.如果用的異步task,那麼在onpostexecute裡面去add或者指派就ok了,注意千萬不要在背景去修改類變量的方式去修改資料;