adapter数据的更新

今天在写listview时更新adapter时有时会出现下面的错误

10-07 01:15:58.960: ERROR/AndroidRuntime(13162): 
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(2131165538, class 
android.widget.ListView) with Adapter(class 
android.widget.HeaderViewListAdapter)]

 看下错误说 Make sure the content of your adapter is not modified from a background thread,
but only from the UI thread

 

这可以用主线程的handler解决

可以把需要的数据list1和adapter的list2分成两个;

在handler处理时再把list1赋给list2并通知

 

listAdapter我加了个变量list并写了set方法

listAdapter.setList( list);
listAdapter.notifyDataSetChanged();//通知数据更新
//数据变化和通知我就放一起不会错

 

 

 

你可能感兴趣的:(Adapter)