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 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. [in ListView(2131165287, class android.widget.ListView) with Adapter(class android.widget.ArrayAdapter)]

出现Exception的原因在于:

(1)Adapter在非UI线程中被调用。

(2)Adapter所绑定的数据集,在非UI线程(注意callback方法)中被频繁修改。

解决方案:

使用Handler+Message的方式,将数据处理在UI线程中完成。

注意:数据集修改后,及时调用哪个notifyDataSetChanged()。

你可能感兴趣的:(Android,Tips,ListView,The,content,of,the,adapter)