安卓:为什么长按还触发一个正常的点击? [英] Android: Why does long click also trigger a normal click?

查看:177
本文介绍了安卓:为什么长按还触发一个正常的点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有听众很长的点击和定期点击一个ListView。

I have a ListView with listeners for a long click and a regular click.

为什么,当我长preSS列表项,正规的单击事件被调用呢?

Why, when I long press a list item, the regular click event gets called too?

我需要有两个独立的功能,为不同的点击。

I need to have two separate functions for the different clicks.

推荐答案

事件监听器

<一个href="http://developer.android.com/reference/android/view/View.OnLongClickListener.html#onLongClick%28android.view.View%29">onLongClick() - 这会返回一个布尔值,表明是否已经消耗的情况下,它不应该再进行。也就是说,返回true,以表明您已经处理的事件,它应该到此为止;返回false,如果你还没有处理它和/或事件应继续任何其他的点击监听器。

onLongClick() - This returns a boolean to indicate whether you have consumed the event and it should not be carried further. That is, return true to indicate that you have handled the event and it should stop here; return false if you have not handled it and/or the event should continue to any other on-click listeners.

您返回 onLongClick()并仍然得到正常的单击事件?

Are you returning true from your onLongClick() and still getting the normal click event?

编辑补充:对于一个ListView,您可以使用 OnItemLongClickListener 。该<一href="http://developer.android.com/reference/android/widget/AdapterView.OnItemLongClickListener.html#onItemLongClick%28android.widget.AdapterView%3C?%3E,%20android.view.View,%20int,%20long%29"><$c$c>onItemLongClick()有使用类似的布尔返回值,表明它是否消耗了此次活动。

Edited to add: For a ListView, you may be using OnItemLongClickListener. The onItemLongClick() there uses a similar boolean return value to indicate whether it consumed the event.

这篇关于安卓:为什么长按还触发一个正常的点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆