如何检测机器人双击? [英] How to detect android double tap?
本文介绍了如何检测机器人双击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检测双击android系统中?我实现OnDoubleTapListener,写这样的:
公共布尔onDoubleTapEvent(MotionEvent E){
// TODO自动生成方法存根
如果(e.getAction()== 1){
Toast.makeText(getApplicationContext(),枪王,Toast.LENGTH_SHORT).show();
}
返回true;
}
但它不工作。什么是问题呢?
解决方案
公共类GestureDoubleTap扩展GestureDetector.SimpleOnGestureListener {
@覆盖
公共布尔onDoubleTap(MotionEvent E){
//一些逻辑
返回true;
}
}
GestureDoubleTap gestureDoubleTap =新GestureDoubleTap();
gestureDetector =新GestureDetector(本/ *中* /,gestureDoubleTap);
view.setOnTouchListener(新View.OnTouchListener(){
@覆盖
公共布尔onTouch(查看视图,MotionEvent motionEvent){
返回gestureDetector.onTouchEvent(motionEvent);
}
});
How to detect the double tap in android? I implement OnDoubleTapListener and wrote this:
public boolean onDoubleTapEvent(MotionEvent e) {
// TODO Auto-generated method stub
if(e.getAction() == 1){
Toast.makeText(getApplicationContext(),"Double Tap", Toast.LENGTH_SHORT).show();
}
return true;
}
But it is not working. What is the wrong with this?
解决方案
public class GestureDoubleTap extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDoubleTap(MotionEvent e) {
//some logic
return true;
}
}
GestureDoubleTap gestureDoubleTap = new GestureDoubleTap();
gestureDetector = new GestureDetector(this/* context */, gestureDoubleTap);
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return gestureDetector.onTouchEvent(motionEvent);
}
});
这篇关于如何检测机器人双击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文