AdapterView的onItemClickListener和OnItemSelectedListener的区别
这两个侦听器之间有什么区别,文档说:
OnItemSelectedListener - 选择此视图中的项目时调用的回调的接口定义。
OnItemClickListener - 单击此 AdapterView 中的项目时调用的回调的接口定义。
选择、点击在触摸屏上不都是一样的吗?
What is the difference between these two listeners,documentation says :
OnItemSelectedListener - Interface definition for a callback to be invoked when an item in this view has been selected.
OnItemClickListener - Interface definition for a callback to be invoked when an item in this AdapterView has been clicked.
Selection,Click aren't these equal on touch screen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
OnItemSelectedListener 用于 Spinners,OnItemClickListener 用于 ListViews。
OnItemSelectedListener is used for Spinners, and OnItemClickListener is used for ListViews.
仅当新选择的位置与先前选择的位置不同或者没有选择的项目时,才会调用 AdapterView.OnItemSelectedListener。
但是,即使您每次单击同一个项目,也会调用 AdapterView.OnClickListener。
http://developer.android.com/reference/android/widget/AdapterView.OnItemSelectedListener.html< /a>
AdapterView.OnItemSelectedListener is invoked only when the newly selected position is different from the previously selected position or if there was no selected item.
However AdapterView.OnClickListener is invoked even you click the same item everytime.
http://developer.android.com/reference/android/widget/AdapterView.OnItemSelectedListener.html
Android 区分了选择事件和点击事件。
基于“旋转器”范例的小部件(包括旋转器和画廊)将所有内容视为选择事件。其他小部件(例如 ListView 和 GridView)以不同的方式处理选择事件和单击事件。对于这些小部件,选择事件由定点设备驱动,例如使用箭头键在列表中上下移动突出显示栏。单击事件是指用户“单击”定点设备(例如,按下中心方向键按钮)或使用触摸屏点击小部件中的某些内容。
(来源:摘自《忙碌的程序员 Android 开发指南》3.8 版)
Android makes a distinction between selection events and click events.
Widgets based off of the “spinner” paradigm — including Spinner and Gallery — treat everything as selection events. Other widgets — like ListView and GridView — treat selection events and click events differently. For these widgets, selection events are driven by the pointing device, such as using arrow keys to move a highlight bar up and down a list. Click events are when the user either “clicks” the pointing device (e.g., presses the center D-pad button) or taps on something in the widget using the touchscreen.
(source: Excerpt from "The Busy Coder's Guide to Android Development" Version 3.8)