Android - Getting database ID from ListView selection

后端 未结 2 1979
温柔的废话
温柔的废话 2021-01-28 17:07

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

2条回答
  •  Happy的楠姐
    2021-01-28 17:37

    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
        }
    });
    

提交回复
热议问题