Answer the question
In order to leave comments, you need to log in
How to get the id or position of an element on click?
I am using RecyclerView + SQLite to store and display items. When clicking, you need to pass the ID (of this element from the database) through the intent to another activity.
There is a method that implements getting data from the database (_id and product name).
If you specify the code below, then when you click on an element in another activity, I get numbers from 3 to 9 (this is clearly not the ID of the selected element).
descriptionIntent.putExtra("drugID", mCursor.getString(mCursor.getColumnIndex("_id")));
descriptionIntent.putExtra("drugID", mCursor.getPosition());
Answer the question
In order to leave comments, you need to log in
Write down the id at the stage of obtaining from the source. For example map to data-classes. Cursor at a particular moment always looks at one particular line, so you get not the IDs of the elements you clicked on, but the ID from the current cursor position.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question