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

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

问题描述

我有一个带有监听器的 ListView,用于长按和常规单击.

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.

推荐答案

来自 事件监听器:

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() 返回 true 并且仍然获得正常的点击事件?

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

编辑添加:对于 ListView,您可能正在使用 OnItemLongClickListener.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.

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

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