java - asyncTask and Context -
this code custom array adapter constructor
public class customarrayadapter extends arrayadapter<string> { rowitems rowitems; list<rowdata> datalist; public customarrayadapter(context context, int textviewid, string[] id, rowitems rowitems, list<rowdata> listdata) and eclipse trys change in asynctask , asynctask
private class asynctaskproduct extends asynctask<void, void, boolean>{ string url; string result; context mycontex; progressdialog pd; string[] id; list<rowdata> l; listview lvproduct; public asynctaskproduct(string url, context contex,listview lv) { url = url; mycontex = contex; lvproduct = lv; } @override protected void onpreexecute() { super.onpreexecute(); pd = new progressdialog(mycontex); pd.setmessage("file downloading ..."); pd.setcancelable(false); pd.setprogressstyle(progressdialog.style_spinner); pd.show(); } @override protected boolean doinbackground(void... arg0) { boolean state = false; getjsonresult con = new getjsonresult(); result = con.postforjson(url); if (result != null){ state = true; result = result.substring(10, result.length() - 1); } return state; }; protected void onpostexecute(boolean state) { if (state) { (int = 0; < l.size(); i++) { id [i]=string.valueof(i); } lvproduct.setadapter(new customarrayadapter(this,r.id.lvrow_tv_id, id, new rowitems(), l)); toast.maketext(mycontex,result, toast.length_short).show(); }else { toast.maketext(mycontex,"error", toast.length_short).show(); } pd.cancel(); } my error lvproduct.setadpter. eclips constructor undefined , try change
customarrayadapter(**asynctaskproduct**, int textviewid, string[] id, rowitems rowitems, list<rowdata> listdata) why change context asynctaskproduct?!!
new customarrayadapter(this,r.id.lvrow_tv_id, id, new rowitems(), l)); in statement first parameter not context. instance of asynctask. need pass context parameter. try instead
new customarrayadapter(yourcontext ,r.id.lvrow_tv_id, id, new rowitems(), l)); now question yourcontext.. if declaring asynctask within activity (or extends context).. can use classname.this.....
if not better pass context in asynctask
Comments
Post a Comment