@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ListView lView = (ListView) parent; Person person = (Person) lView.getItemAtPosition(position); Toast.makeText(getApplicationContext(), person.getId().toString(), Toast.LENGTH_SHORT).show(); // Cursor cursor=(Cursor) lView.getItemAtPosition(position); // int personid=cursor.getInt(cursor.getColumnIndex("_id")); // Toast.makeText(getApplicationContext(), personid+"" , Toast.LENGTH_SHORT).show(); }
private void show() { List<Person> persons = personService.getScrollData(0, 20); List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>(); for (Person person : persons) { HashMap<String, Object> item = new HashMap<String, Object>(); item.put("name", person.getName()); item.put("age", person.getAge()); item.put("phone", person.getPhone()); item.put("id", person.getId()); data.add(item); } SimpleAdapter adapter = new SimpleAdapter( this, data, R.layout.item, new String[] {"name", "age", "phone"}, new int[] {R.id.name, R.id.age, R.id.phone}); listView.setAdapter(adapter); }