![android The content of the adapter has changed but ListView did not receive a notification 错误的解决方案 android The content of the adapter has changed but ListView did not receive a notification 错误的解决方案](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
使用了AsyncTask在后台刷新适配器,并且通知ui线程更新ListView,运行时发现时不时的出现 如题 的错误,
导致程序崩溃,解决方法如下:
1.建立一个缓冲数据集,这个数据集就是填充适配器的数据集,如ArrayList<String>
2.在AsyncTask的后台方法(doInBackground)中将数据添加至缓冲数据集中,然后调用onProgressUpdate通知更新
3.在onProgressUpdate方法中,将缓冲数据集的数据添加至原数据集中,然后将缓冲数据集中的数据清空
注意:访问缓冲数据集的时候,需要加上同步锁 synchronized