Android - Getting database ID from ListView selection
I have a ListView lv which uses a Cursor c from an SQL database to populate it. When an item is selected however, I need to get the ID of the row. How can I do this? I assume that you are using a SimpleCursorAdapter (or similar), so I would use the OnItemClickListener : listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // id references the SQLiteDatabase _id column } }); Here's how it worked out for me. In an other class, I have created a method of List type and added the column id & the name