listview提示The content of the adapter has changed but ListView did not receive a notification

来源:互联网 发布:网络女主播大闹机场 编辑:程序博客网 时间:2024/05/08 23:44

listview在适配数据时,滚动listview的时候会报错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. [in ListView(2131230914, class android.widget.ListView) with Adapter(class android.widget.HeaderViewListAdapter)]


经研究是adapter在handler里面多次创建对象导致,解决方法:

1、在handler里面判断adapter,如果为null,创建一次,之后就不再创建

2、在oncreate里面创建adapter,并适配给listview,数据为0,在handler里面只是notifyDataSetChanged()

0 0
原创粉丝点击