i have following json array:
{ "id": "c200", "name": "ravi tamada", "email": "ravi@gmail.com", "address": "xx-xx-xxxx,x - street, x - country", "gender" : "male", "phone": { "mobile": "+91 0000000000", "home": "00 000000", "office": "00 000000" } }, { "id": "c201", "name": "johnny depp", "email": "johnny_depp@gmail.com", "address": "xx-xx-xxxx,x - street, x - country", "gender" : "male", "phone": { "mobile": "+91 0000000000", "home": "00 000000", "office": "00 000000" } }
i displaying name, email , mobile in main activity , passing them singleitem activity, need send address second activity not in main activity. how can this?
here code:
// contacts jsonarray jsonarray contacts = null; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); // hashmap listview arraylist<hashmap<string, string>> contactlist = new arraylist<hashmap<string, string>>(); // creating json parser instance jsonparser jparser = new jsonparser(); // getting json string url jsonobject json = jparser.getjsonfromurl(url); try { // getting array of contacts contacts = json.getjsonarray(tag_contacts); // looping through contacts for(int = 0; < contacts.length(); i++){ jsonobject c = contacts.getjsonobject(i); // storing each json item in variable string id = c.getstring(tag_id); string name = c.getstring(tag_name); string email = c.getstring(tag_email); string address = c.getstring(tag_address); string gender = c.getstring(tag_gender); // phone number agin json object jsonobject phone = c.getjsonobject(tag_phone); string mobile = phone.getstring(tag_phone_mobile); string home = phone.getstring(tag_phone_home); string office = phone.getstring(tag_phone_office); // creating new hashmap hashmap<string, string> map = new hashmap<string, string>(); // adding each child node hashmap key => value map.put(tag_id, id); map.put(tag_name, name); map.put(tag_email, email); map.put(tag_phone_mobile, mobile); // adding hashlist arraylist contactlist.add(map); } } catch (jsonexception e) { e.printstacktrace(); } /** * updating parsed json data listview * */ listadapter adapter = new simpleadapter(this, contactlist, r.layout.list_item, new string[] { tag_name, tag_email, tag_phone_mobile }, new int[] { r.id.name, r.id.email, r.id.mobile }); setlistadapter(adapter); // selecting single listview item listview lv = getlistview(); // launching new screen on selecting single listitem lv.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { // getting values selected listitem string name = ((textview) view.findviewbyid(r.id.name)).gettext().tostring(); string cost = ((textview) view.findviewbyid(r.id.email)).gettext().tostring(); string description = ((textview) view.findviewbyid(r.id.mobile)).gettext().tostring(); // starting new intent intent in = new intent(getapplicationcontext(), singlemenuitemactivity.class); in.putextra(tag_name, name); in.putextra(tag_email, cost); in.putextra(tag_phone_mobile, description); startactivity(in); } }); }
pass address activity singlemenuitemactivity
in.putextra(tag_address, address);
and if going call second activity singlemenuitemactivity intent there using bundle hope got ..then similary pass intent there intent in = new intent(getapplicationcontext(), yoursecondactivity.class); address = // intent have main acitivyt
in.putextra(tag_address2, address); startactivity(in);
Comments
Post a Comment