android - ListView in OnpostExecute and display respective info -
sir have written code custom list view perfectely fine want write code onitem click listenet in onpostexecutemethod , show respective info according ticket. want show ticket info of selected item.
class viewticket extends asynctask<string, void, string> { @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(userlogedin.this); pdialog.setmessage("loading...."); pdialog.setindeterminate(false); pdialog.setcancelable(false); pdialog.show(); } @override protected string doinbackground(string... params) { list<namevaluepair> param = new arraylist<namevaluepair>(); param.add(new basicnamevaluepair("userid", u_id)); // jsonobject jsonarray = jpar.makehttprequest(urlmyticket, "post", param); servicehandler sh = new servicehandler(); string jsonstr = sh.makeservicecall(urlmyticket, servicehandler.post, param); log.d("response: ", "> " + jsonstr); if (jsonstr != null) { try { contacts = new jsonarray(jsonstr); a=contacts.length(); log.v(tag, ".................." + a); if(a > 0 ) { id = new string[contacts.length()]; stats = new string[contacts.length()]; due_date = new string[contacts.length()]; prob = new string[contacts.length()]; (int = 0; < contacts.length(); i++) { jsonobject c = contacts.getjsonobject(i); string aa = c.getstring(tag_id); string bb = c.getstring(tag_prob); string cc = c.getstring(tag_status); string dd = c.getstring(tag_due_date); log.v(tag, "tag_id" + aa); log.v(tag, "tagprob" + bb); log.v(tag, "tagprob" + cc); log.v(tag, "tagprob" + dd); id[i] = aa; prob[i] = bb; stats[i] = cc; due_date[i] = dd; log.v(tag, "aaaaa" + id[i]); log.v(tag, "bbbbb" + prob[i]); log.v(tag, "cccc" + stats[i]); log.v(tag, "dddd" + due_date[i]); } } } catch (jsonexception e) { system.out.print("hiiiiiiiiiiii" ); e.printstacktrace(); } } return null; } @override protected void onpostexecute(string result) { super.onpostexecute(result); // dismiss progress dialog log.v(tag, "length of aaaaa" + a); if(id!=null && id.length > 0 ) { ticket_adapter adapter=new ticket_adapter(userlogedin.this,id,prob,stats,due_date,stimg); lv.setadapter(adapter); lv.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> adapterview, view view, int i, long l) { //how write code send ticket releated data next activity of respective ticket } }); } else { toast.maketext(userlogedin.this, "no ticket present", toast.length_short).show(); } pdialog.hide(); pdialog.dismiss(); } }
if ticket data being held in model class, ticket
or of sort, suggest having implement parcelable
, passing related activity in intent, intent.putextra(string, parcelable)
, , recreating model class in new activity parcelable data new ticket(parcelable)
. if small amount of info (names, numbers, etc.) pass them directly though intent, intent.putextra(string, string)
.
Comments
Post a Comment