I`m using JSON to parse data from mysql table, with "id" and "firstname" rows, and populate listview with "firstname" row and its working fine. But, I want to add onListItemClick and when user clicks on some name on listview, the "id" value for that name should be forwarded to another class. This is how I populate listview:
JSONArray jArray = new JSONArray(result);
JSONObject json_data = null;
for (int i = 0; i < jArray.length(); i++) {
json_data = jArray.getJSONObject(i);
r.add(json_data.getString("firstname"));
}
dataAdapter = new ArrayAdapter<String>(Persons.this,
R.layout.person_row, r);
ListView lv = (ListView) findViewById(android.R.id.list);
lv.setAdapter(dataAdapter);
and I can forward "firstname" to other class with this:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Object o = this.getListAdapter().getItem(position);
String FirstName = o.toString();
Intent i = new Intent(this, PersonDetails.class);
Bundle bandl = new Bundle();
bandl.putString("fn", FirstName);
i.putExtras(bandl);
startActivity(i);
}
But the problem is that I want to display "firstname" on listview and onClick to forward only "id" to other class, and I cant figure that out. Forwarding "firstname" to other class and then retreiving other mysql data worked fine until I got two people with same name, so that`s why I need to forward row "id" ...