java.lang.IllegalStateException:The content of the adapter has changed but ListView did not receiv问题
2018-03-27 00:14
519 查看
在使用ListView过程中,有时会出现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. Make sure your adapter calls notifyDataSetChanged() when its content changes.
原因是给ListView设置的adapter,修改数据源时放在了非UI线程中去执行,在主线程中调用adapter的notifyDataSetChanged()方法,有时会抛出此异常,(亦即,当ListView缓存的数据Count和ListView中Adapter.getCount()不等时,会抛出该异常。)因此,修改adapter数据源时需要放在主线程中去执行,这里给出两种思路。
1.修改数据时可以为adapter的数据源复制一个副本,在子线程中修改副本的数据即可,然后在主线程中将副本赋值给adapter数据源即可。
2.直接在主线程中修改adapter的数据源。通过Activity.runOnUiThread()方法,Handler机制和AsyncTask均可实现。
作者:Drc15H
链接:https://www.jianshu.com/p/182174d63557
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
原因是给ListView设置的adapter,修改数据源时放在了非UI线程中去执行,在主线程中调用adapter的notifyDataSetChanged()方法,有时会抛出此异常,(亦即,当ListView缓存的数据Count和ListView中Adapter.getCount()不等时,会抛出该异常。)因此,修改adapter数据源时需要放在主线程中去执行,这里给出两种思路。
1.修改数据时可以为adapter的数据源复制一个副本,在子线程中修改副本的数据即可,然后在主线程中将副本赋值给adapter数据源即可。
2.直接在主线程中修改adapter的数据源。通过Activity.runOnUiThread()方法,Handler机制和AsyncTask均可实现。
作者:Drc15H
链接:https://www.jianshu.com/p/182174d63557
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
相关文章推荐
- java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receiv
- java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification
- java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive
- java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive
- java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive
- java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive
- java.lang.IllegalStateException: The content of the adapter has changed but ListView...的问题
- The content of the adapter has changed but ListView did not receive a notification,java.lang.IndexOu
- java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive
- java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive
- java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive
- java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive
- java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive
- 解决ListView的The content of the adapter has changed but ListView did not receive a notification崩溃问题
- Android问题3-ListView Adapter(The content of the adapter has changed but ListView did not receive a n)
- 解决问题The content of the adapter has changed but ListView did not receive a notification.
- 解决java.lang.IllegalStateException: The content of the adapter has changed but ListView...的问题
- listview刷新点击,出现The content of the adapter has changed but ListView did not receive a notification问题
- 解决java.lang.IllegalStateException: The content of the adapter has changed but ListView...的问题
- 解决The content of the adapter has changed but ListView did not receive a notification的问题