最近在做一个文件浏览器的模块,采用分步显示数据而不是等待加载完成后再一次性加载,但在编写过程中发现,在异步线程中添加Listview的Adapter的数据时,当数据未加载完成点击Listvew的Item时,会出现如下异常:
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.
搜索相关资料后整理出解决办法如下:
将异步线程中添加Adapter数据的代码移出至回调时添加。
注:需要注意不能让UI线程负荷太重。