`

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();//通知数据更新
//数据变化和通知我就放一起不会错

 

 

 

分享到:
评论
2 楼 jayaaaiii 2011-11-08  
其实也就是在你 notifyDataSetChanged() 的这个函数里面产生了线程安全问题,。。是对于adapter中的getCount的数值发生了变化。才倒至的。
1 楼 jayaaaiii 2011-11-08  
不错。这是个好办法。。

相关推荐

Global site tag (gtag.js) - Google Analytics