解决适配器的内容已更改,但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. Make sure your adapter calls notifyDataSetChanged() when its content changes. 

解决方法:

1.适配器里主要是添加这两个方法来接受数据:

public void addItem(List<GetAuthorizedListModel> list) {
    listModel.addAll(list);
    notifyDataSetChanged();
}

public void setItem(List<GetAuthorizedListModel> list) {
    listModel.clear();
    listModel.addAll(list);
    notifyDataSetChanged();
}

2.activity里获取数据和调用方法:

private void getPushListInfo() {
    networkInfo.getPushList(viewSearchSearch.getText().toString(), page, new CallBack() {
        @Override
        public void onResponse(String response) {
            GetPushModel info = gson.fromJson(response, GetPushModel.class);
            if (info.getErrorCode() == 0) {
                if (info.getR_list().get(0).getListModel() != null && info.getR_list().get(0).getListModel().size() > 0) {
                    totalPages = info.getR_list().get(0).getNO_TOTAL_PAGE();
                    listPush.addAll(info.getR_list().get(0).getListModel());
                    if (page == 1) {
                        pushAdapter.setItem(info.getR_list().get(0).getListModel());
                        refreshLoadMore.stopRefresh();
                    } else {
                        pushAdapter.addItem(info.getR_list().get(0).getListModel());
                        refreshLoadMore.stopLoadMore();
                    }
                } else {
                    if (page == 1) {
                        pushAdapter.setItem(listPush);
                        refreshLoadMore.stopRefresh();
                    }
                }
            } else if (info.getErrorCode() == 403) {
                saveAccountAndTokenAndLogin("", "", false);
                intentJumpLoginActivity(0);
            } else {
                showToast(info.getErrorMsg());
                if (page == 1) {
                    refreshLoadMore.stopRefresh();
                    pushAdapter.setItem(listPush);
                } else {
                    refreshLoadMore.stopLoadMore();
                }
            }
        }
    });
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值