I have a scenario here,i want to pass the desired json object on the list item click in my below activity
suppose when i click deal 2
2nd json object from jArray should be passed to intent and my next activity must get it.
but problem here is that when i click any of the list items the next activity receives json object at last index .
here is my code from 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 to put this 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 to solve this i have to put my list.setOnItemClickListener()
at proper place but i am confused where to put it,so that when i click on deal1
the 1st json object will be passed to intent