java - Android call notifyDataSetChanged from AsyncTask -
i've custom listadapter fetches data internet in asynctask.
the data added list, when try operations application crashes...
i'm sure because i'm calling notifydatasetchanged(); @ wrong time (i.e. before asynctask ends).
what i've got now:
public class mylistadapter extends baseadapter { private arraylist<string> mstrings = new arraylist<string>(); public mylistadapter() { new retreivestringstask().execute(internet_url); //here call notify function **************** this.notifydatasetchanged(); } class retreivestringstask extends asynctask<string, void, arraylist<string>> { private exception exception; @override protected arraylist<string> doinbackground(string... urls) { try { url url= new url(urls[0]); //return arraylist return getstringsfrominternet(url);; } catch (exception e) { this.exception = e; log.e("asynctask", exception.tostring()); return null; } } @override protected void onpostexecute(arraylist<string> stringsarray) { //add tours internet array if(stringsarray != null) { mstrings.addall(toursarray); } } } }
my question is: can call notifydatasetchanged() onpostexecute function in asynctask or @ other time when asynctask has fetched data?
can call notifydatasetchanged() onpostexecute function in asynctask
yes, can call notifydatasetchanged()
onpostexecute
update adapter data when doinbackground
execution complete. as:
@override protected void onpostexecute(arraylist<string> stringsarray) { //add tours internet array if(stringsarray != null) { mstrings.addall(toursarray); // call notifydatasetchanged() here... mylistadapter.this.notifydatasetchanged(); } }
Comments
Post a Comment