java - Parsing a ListView item onclick to another activity and match a specific data from JSON -


can me parse listview item on click activity preferably 1 , match parsed id json data. working on volley library , want related data of specific item clicked.

        // called when activity first created.     @override     public void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);              linkedlist<string> mlinked = new linkedlist<string>();             (int = 0; < drugs.length; i++) {                     mlinked.add(drugs[i]);             }              setlistadapter(new mylistadaptor(this, mlinked));              listview lv = getlistview();             lv.setfastscrollenabled(true);              lv.setonitemclicklistener(new onitemclicklistener() {                     public void onitemclick(adapterview<?> parent, view view, int position, long id) {                             // when clicked, show toast textview text                             toast.maketext(getapplicationcontext(), ((textview) view).gettext(), toast.length_short).show();                              // start new intent passing value                             // end intent                     }              });        } 

i needed value seen on activity as

public class activity2_view extends activity { 

// collecting values mainactivity class textview tvview;

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_result);      tvview = (textview) findviewbyid(r.id.tvview);     intent intent = getintent();      string itemname = intent.getstringextra("jsonid");      tvview.settext("your drug name is: "  + itemname); } 

}

in adapter, in getview() method, can set tag match id of json data need link with. example:

@override public view getview(int position, view convertview, viewgroup parent) {     int jsonid;  // set view's tag id of json data                  // want link to.     convertview.settag(jsonid); } 

then, in onitemclicklistener:

listview lv = getlistview(); lv.setfastscrollenabled(true);  lv.setonitemclicklistener(new onitemclicklistener() {     public void onitemclick(adapterview<?> parent, view view, int position, long id) {         // when clicked, show toast textview text         toast.maketext(getapplicationcontext(), ((textview) view).gettext(), toast.length_short).show();          // id view.         int jsonid = (int) view.gettag();          // start new intent passing value         intent newactivityintent = new intent(youractivity.this, yournewactivity.class);         newactivityintent.putextra("jsonid", jsonid);          // start it.         startactivity(newactivityintent);     } }); 

if you're using viewholder in getview() method optimization purposes, viewholder tag of view. need add member property viewholder object can save id with.

public class viewholder {     private int mjsonid;     private textview mtextview;      public void setid(int id) {         mjsonid = id;     }      public int getjsonid() {         return mjsonid;     } } 

then

viewholder viewholder = (viewholder) view.gettag(); int jsonid = viewholder.getjsonid(); 

hope helps.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -