I am trying to show database values into a Listview but, I set position of element manually (e.g. if(position==0){}) to do the intent to next activity. But i want to show these element according to their id, name, and mobile (i.e. for 1st element activity can parse these parameter to next activity, for 2nd parameters can hold their appropriate value...etc). so how can i perform this!
List.java
protected void showList(){
try {
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray(TAG_RESULTS);
for(int i=0;i<peoples.length();i++){
JSONObject c = peoples.getJSONObject(i);
String id = c.getString(TAG_ID);
String name = c.getString(TAG_NAME);
String mobile = c.getString(TAG_MOB);
HashMap<String,String> persons = new HashMap<String,String>();
persons.put(TAG_ID,id);
persons.put(TAG_NAME,name);
persons.put(TAG_MOB,mobile);
personList.add(persons);
}
ListAdapter adapter = new SimpleAdapter(
User_List.this, personList, R.layout.list_item,
new String[]{TAG_ID,TAG_NAME,TAG_MOB},
new int[]{R.id.id, R.id.name, R.id.mobile}
);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position==0) {
Intent intent = new Intent(User_List.this, MapsActivity.class);
startActivity(intent);
}
}
});
} catch (JSONException e) {
e.printStackTrace();
}