简体   繁体   English

ListView在onClickListener上获取项目ID

[英]ListView get item id on onClickListener

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

Instead of using OnClickListener I would use OnItemClickListener . 而不是使用OnClickListener我将使用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. 其中第四个参数是您单击的项目的ID。

See the documentation for more info. 请参阅文档以获取更多信息。

You should probably implement OnItemClickListener http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html 您可能应该实现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 方法abstract void onItemClick(AdapterView<?> parent, View view, int position, long id)将为您提供被单击的行的位置和ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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