Android:为什么长时间点击也会触发正常点击? [英] Android: Why does long click also trigger a normal click?

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

问题描述



为什么当我长按一个列表项时,常规点击事件也被调用了



我需要有两个不同的点击功能。

解决方案

事件侦听器


onLongClick() - 这将返回一个布尔值,以指示是否已使用该事件,并且不应进一步传递该事件。也就是说,返回真实表明你已经处理了事件,它应该停在这里;如果您没有处理它,则返回false,并且/或者该事件应该继续到任何其他点击式监听器。


code> true 从您的 onLongClick()仍然得到正常的点击事件?



已编辑添加:对于ListView,您可能使用 OnItemLongClickListener onItemLongClick() 使用类似的布尔值返回值来指示是否使用该事件。 >

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

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.

解决方案

From Event Listeners:

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.

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

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.

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

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