android The content of the adapter has changed but ListView did not receive a notification 错误的解决方案

使用了AsyncTask在后台刷新适配器,并且通知ui线程更新ListView,运行时发现时不时的出现 如题 的错误,

导致程序崩溃,解决方法如下:

1.建立一个缓冲数据集,这个数据集就是填充适配器的数据集,如ArrayList<String>

2.在AsyncTask的后台方法(doInBackground)中将数据添加至缓冲数据集中,然后调用onProgressUpdate通知更新

3.在onProgressUpdate方法中,将缓冲数据集的数据添加至原数据集中,然后将缓冲数据集中的数据清空

注意:访问缓冲数据集的时候,需要加上同步锁 synchronized

原文地址:https://www.cnblogs.com/trenail/p/3388019.html