In my application I need to move from one activity to another depending on the list clicked. In each listview there will be three textview namely: Emp_id, Emp_name,Emp_address, so whenever I click on a particular list that should move to next activity of the corresponding Emp_id. So here I want to catch the Emp_id, which I am unable. I have tried a lot but got only the first Emp_id not the list that I have clicked.
CODE:
ArrayList<HashMap<String, String>> mylist2 = new ArrayList<HashMap<String, String>>();
try{
JSONObject jObj = new JSONObject(Mydetail);
JSONArray data = jObj.getJSONArray("mydata");
for(int i=0;i<data.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = data.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("Eid", "" + e.getString("E_id"));
map.put("Ename", "" + e.getString("E_name"));
map.put("Eaddress", "" + e.getString("E_address"));
mylist2.add(map);
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
ListAdapter adapter = new SimpleAdapter(this, mylist2 , R.layout.datalist,
new String[] { "Eid", "Ename", "Eaddress" },
new int[] { R.id.TextView1,R.id.TextView2e,R.id.TextView3 });
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
//String val = o.get("id");
Pnm = (TextView)findViewById(R.id.TextView1);
String str = ((TextView)Pnm).getText().toString();
Toast.makeText(projects.this, str,Toast.LENGTH_LONG).show();
Intent newActivitySecond = new Intent(projects.this, modules.class);
projects.this.startActivity(newActivitySecond);
}
});
Thanks
Try like this: