如何检测onLongClick ACTION_UP事件? [英] How to detect onLongClick ACTION_UP event?
问题描述
我有一个同时实现了 OnClickListener
和 OnLongClickListener
图像。在 OnLongClickListener
在preSS下降( ACTION_DOWN
)我启动一个定时器。我想在 ACTION_UP
取消它。
I have an image which implements both OnClickListener
and OnLongClickListener
. In the OnLongClickListener
at press down (ACTION_DOWN
) I start a timer. I want to cancel it at ACTION_UP
.
现在,如果我执行 OnTouchListener
此图像,然后我抓住 ACTION_DOWN
正常点击。我想赶上龙点击而已。
Now, if I implement OnTouchListener
for this image, then I catch ACTION_DOWN
for normal clicks. And I want to catch Long clicks ONLY.
为什么不长按消防 ACTION_UP
事件?我怎样才能检测到这个事件,并停止计时器。
Why does not long click fire ACTION_UP
event? How can I detect this event and stop the timer.
如果你需要一个code,我可以将它张贴,但我不认为它会帮助你,因为在code没有错误。
If you need a code, I can post it, but I do not think it will help you as there is no errors in the code.
PS。在任何特定的时间或价值,我不能停止计时器,因为这漫长preSS持续增加另一个元素的值。这一增长过程中,应停止只能在图像长preSS ACTION_UP
。
PS. I cannot stop the timer at any specific time or value as this long press continuously increase the value of another element. This increase process should stop only at image long press ACTION_UP
.
推荐答案
只需使用OnTouchListener,忘记OnLongClickListener。您可以检测很长的点击通过检查坐标和pressed时候,你在()由OnTouch通过MotionEvent对象。
Just use OnTouchListener and forget about OnLongClickListener. You can detect a long click by checking coordinates and pressed time, you have all that info in MotionEvent object passed by OnTouch().
1 - 要检查坐标,从您的ImageView的容器使用的getX()和getY()以从MotionEvent和getDrawingRect()。
1- To check coordinates, use getX() and getY() from MotionEvent and getDrawingRect() from your ImageView container.
2 - 要检查pressed时间,使用getEventTime(),存储第一时间ACTION_DOWN,然后随着时间的推移在ACTION_UP事件减去计算。你可以承担像800毫秒的长按。
2- To check for pressed time, use getEventTime(), storing first time in ACTION_DOWN and then compute by substracting with time in ACTION_UP event. You could assume like 800mS for a long click.
这篇关于如何检测onLongClick ACTION_UP事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!