android - AsyncTask won't let me use my own class -
i have asynctask load entries in listview creating everytime new instance of class, varaibles saved , let them load own adapter extended baseadapter.
the class looks this:
public class pictureresults { private long id; private string pictureurl; public void setid(long id) { this.id = id; } public long getid() { return id; } public void setpictureurl(string pictureurl) { this.pictureurl = pictureurl; } public string getpictureurl() { return pictureurl; } } this asynctask class:
private class getpicturedatatask extends asynctask<long, string, void> { protected pictureresults doinbackground(long... param) { pictureresults pr; pr = new pictureresults(); pr.setid(param[0]); pr.setpictureurl("http://www.myurl.com"); return pr; } protected void onprogressupdate(string... response) { //do nothing } protected void onpostexecute(pictureresults ret) { picresults.add(ret); //picresults arraylist<pictureresults> ret.loadpicture(customadapter); customadapter.notifydatasetchanged(); } } the main problem appears eclipse let me know following:
the return type incompatible asynctask<long,string,void>.doinbackground(long[]) it important customadapter.notifydatasetchanged(); executed in onpostexecute because in onprogressupdate app crashes causing of changing listview background thread.
why can't use pictureresults type???
btw: how execute asynctask:
long hey = (long) 1; new getpicturedatatask().execute(hey);
the third type parameter of asynctask should pictureresults not void
class getpicturedatatask extends asynctask<long, string, pictureresults> because 3rd parameter type of asynctask kind of data result should returned. if don't want return result doinbackground(), use void , return null;
Comments
Post a Comment