Android call notifyDataSetChanged from AsyncTask

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 13:13:33

can I call notifyDataSetChanged() from the onPostExecute function in the AsyncTask

Yes, you can call notifyDataSetChanged() from onPostExecute to Update Adapter data when doInBackground execution complete. do it as:

@Override
protected void onPostExecute(ArrayList<String> stringsArray) {
    //add the tours from internet to the array
    if(stringsArray != null) {
        mStrings.addAll(toursArray);
        // call notifyDataSetChanged() here...
         MyListAdapter.this.notifyDataSetChanged();
    }
}

Call notifyDataSetChanged() in onPostExecute() as

@Override
        protected void onPostExecute(ArrayList<String> stringsArray) {
            //add the tours from internet to the array
            if(stringsArray != null) {
                mStrings.addAll(toursArray);
MyListAdapter.this.notifyDataSetChanged();
            }
        }

have you tried calling it in the onPostExecute method of the ASyncTask. the onPreExecute and on onPostExecute are used to update the UI.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!