我正在尝试更新我的列表并在我的活动中显示更新后的列表。每次我这样做我都会收到以下错误
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.
这是我的代码,我正在使用 AsyncTask 来完成此任务。我在我的适配器上调用 notifyDataSetChanged() 但它似乎不起作用。我究竟做错了什么?
class MyTask extends AsyncTask<Context, Integer, String> {
@Override
protected String doInBackground(Context... params) {
GregorianCalendar currentDateclone = (GregorianCalendar) currentDate.clone();
ListPopulater2.listPopulate(currentDateclone, 7, items, Id);
//method to update list info
}
// -- gets called just before thread begins
@Override
protected void onPreExecute() {
progressdialog = ProgressDialog.show(SectionListExampleActivity.this, "", "Loading..."); //display progress bar
super.onPreExecute();
}
// -- called as soon as doInBackground method completes
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Log.d("postExecute", "here");
adapter.notifyDataSetChanged();
progressdialog.cancel();
}
}