问题: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(); } } } }); }