看了下源代码ListView.java里面
else if (mItemCount != mAdapter.getCount()) {
throw new 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(" + getId() + ", " + getClass()
+ ") with Adapter(" + mAdapter.getClass() + ")]");
}
Adapter有更新没告诉listview。
我原来的代码,
new AsyncTask(){
@Override
protected Object doInBackground(Object[] objects) {
mList = getImageList();
return null;
}
@Override
protected void onPostExecute(Object result) {
mListAdapter.notifyDataSetChanged();
}
}.execute();
改为
new AsyncTask<Object, Object, List<Data>>(){
@Override
protected List<Data> doInBackground(Object[] objects) {
List<Data> result = getImageList();
return result;
}
@Override
protected void onPostExecute(List<Data> result) {
mList = result;
mListAdapter.notifyDataSetChanged();
}
}.execute();
Adapter更新跟notifyDataSetChanged都在ui线程了。