android - passing JSON object to another activity on list item click -


i have scenario here,i want pass desired json object on list item click in below activity

activity alldeals

suppose when click deal 2 2nd json object jarray should passed intent , next activity must it.

but problem here when click of list items next activity receives json object @ last index final deal activity.

here code alldeals.java

try{             jarray = new jsonarray(result);             for(int i=0;i<jarray.length();i++){                     json_data = jarray.getjsonobject(i);                      log.i("log_tag","dealid: "+json_data.getstring("deal_id")+                             ", hotel name: "+json_data.getstring("hotel_name")+                             ", location: "+json_data.getstring("location")+                             ", website: "+json_data.getstring("website")                     );              }              json_data=new jsonobject();             string[] data=new string[jarray.length()];             planetlist = new arraylist<string>();                 for(int i=0;i<jarray.length();i++)                 {                     json_data= jarray.getjsonobject(i);                     data[i]=json_data.getstring("deal_id");                     log.i("log_tag", "string "+data[i]);                     planetlist.addall( arrays.aslist("deal "+ (i+1)));                       listadapter = new arrayadapter<string>(this, r.layout.listrow, planetlist);                     runonuithread(new runnable() {                         public void run() {                             list.setadapter(listadapter);                         }                     });                  }                 list.setonitemclicklistener(new onitemclicklistener() {  //where put piece of code???                      public void onitemclick(adapterview<?> arg0, view arg1,                             final int arg2, long arg3) {                      intent intent = new intent(context,finaldeal.class);                       intent.putextra("deal", json_data.tostring());                     startactivity(intent);                                                          }                  });       }     catch(jsonexception e){             log.e("log_tag", "error parsing data "+e.tostring());     } 

i know in order solve have put list.setonitemclicklistener() @ proper place confused put it,so when click on deal1 1st json object passed intent

you can pass jsonobject jsonarray according listview item clicked position as:

list.setonitemclicklistener(new onitemclicklistener() {     public void onitemclick(adapterview<?> arg0, view arg1,                     final int arg2, long arg3) {          if(!jarray.isnull(arg2)){            intent intent = new intent(context,finaldeal.class);              intent.putextra("deal", jarray.optjsonobject(arg2).tostring());            startactivity(intent);                                               }           }      });  

currently passing json_data contain last jsonobject jsonarray when loop execution end


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -