简体   繁体   中英

ListView get item id on onClickListener

通过将OnClickListener设置为android studio中的ListView是否可以获得项目的ID?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM