如何检测为其按钮采用的是Android preSS期 [英] how to detect the period for which a button is press in android
问题描述
有什么办法,我可以检测一个按钮多久preSS?我想捕捉它的一个按钮为preSS并据此采取行动的时间。因此,如果用户保持pressing按键5秒,我想检测在Android上的5秒。
Is there any way i can detect for how long a button is press?? I want to capture the time for which a button is press and act accordingly. So if a user kept pressing the button for 5 sec i want to detect that 5 sec on android.
请让我知道
谢谢
Pranay
Thanks Pranay
推荐答案
给该按钮的 View.OnTouchListener 。您将实现的方法onTouch会给你访问 MotionEvent 。然后,使用getFlags(),你会在用户启动pressing按钮(ACTION_DOWN),当他停下来(ACTION_UP)知道。出现这些情况时,简单地记录系统时间(或作为另一个答案的建议,getDownTime()会给你所需要的时间,但只有当你有ACTION_UP标志)。
Give the button a View.OnTouchListener. The onTouch method you'll implement will give you access to a MotionEvent. Then, using getFlags(), you'll know when the user starts pressing the button (ACTION_DOWN) and when he stops (ACTION_UP). Simply record the system time when these occur (or as suggested in another answer, getDownTime() will give the time you need, but only when you have the ACTION_UP flag).
考虑接受的答案,如果你想更多的人。您的个人资料显示0%接受率。
Consider accepting answers if you want more of them. Your profile show 0% accept rate.
这篇关于如何检测为其按钮采用的是Android preSS期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!