本文介绍了如何测量抽头之间的时间可达毫秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要测量连续抽头以毫秒为单位的时间。我怎样才能做到这一点?
解决方案
查看MyView的;
长previousClickTime;
...
myView.setOnTouchListener(新View.OnTouchListener(){
@覆盖
公共布尔onTouch(视图V,MotionEvent EV)
{
长临时= System.currentTimeMillis的();
如果(previousClickTime!= 0)
{
Log.i(MyView的+(TEMP之间点击=时间 - previousClickTime));
}
其他
{
Log.i(MyView的,首次点击);
}
previousClickTime =温度;
返回true; //注意,您可以返回false,以及任何潜在的意见,然后将接收该触摸事件。
}
}
作为一个侧面说明,如果你想检测双击,尝试 GuestureDetector.setOnDoubleTapListener 。
I want to measure time between consecutive taps in milliseconds. How can I do this?
解决方案
View myView;
long previousClickTime;
...
myView.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent ev)
{
long temp = System.currentTimeMillis();
if (previousClickTime != 0)
{
Log.i("MyView", "Time Between Clicks=" + (temp - previousClickTime));
}
else
{
Log.i("MyView", "First Click");
}
previousClickTime = temp;
return true;//Note that you can return false, and any underlying Views will then receive this touch event.
}
}
As a side note, if you are trying to detect a double click, try GuestureDetector.setOnDoubleTapListener.
这篇关于如何测量抽头之间的时间可达毫秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!