Android Call Notifydatasetchanged From Asynctask
I've a custom ListAdapter that fetches data from internet in an AsyncTask. The data is added perfectly to the list, but when I try to do operations the application crashes... I'm s
Solution 1:
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:
@OverrideprotectedvoidonPostExecute(ArrayList<String> stringsArray) {
//add the tours from internet to the arrayif(stringsArray != null) {
mStrings.addAll(toursArray);
// call notifyDataSetChanged() here...MyListAdapter.this.notifyDataSetChanged();
}
}
Solution 2:
Call notifyDataSetChanged() in onPostExecute() as
@OverrideprotectedvoidonPostExecute(ArrayList<String> stringsArray) {
//add the tours from internet to the arrayif(stringsArray != null) {
mStrings.addAll(toursArray);
MyListAdapter.this.notifyDataSetChanged();
}
}
Solution 3:
have you tried calling it in the onPostExecute method of the ASyncTask. the onPreExecute and on onPostExecute are used to update the UI.
Post a Comment for "Android Call Notifydatasetchanged From Asynctask"