您的位置:首页 > 其它

The content of the adapter has changed but ListView did not receive a notification,

2015-09-14 18:01 435 查看
看了下源代码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线程了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: