Reputation: 118
is it possible to get id of an item by setting OnClickListener to a ListView in android studio?
Upvotes: 0
Views: 596
Reputation: 6717
Instead of using OnClickListener
I would use OnItemClickListener
.
The callback method looks like this:
onItemClick (AdapterView<?> parent, View view, int position, long id)
Where the 4th parameter is the id of your clicked item.
See the documentation for more info.
Upvotes: 1
Reputation: 1904
You should probably implement OnItemClickListener
http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html
The method abstract void onItemClick(AdapterView<?> parent, View view, int position, long id)
will give you the position and the id of the row that was clicked
Upvotes: 0