如何检测视图上的双击?
可能的重复:
Android - 基本手势检测
我正在尝试让 View 对 Android 上的双击敏感。到目前为止,我学会了设置双击并知道在哪里处理操作事件:
API:android.view.GestureDetector.OnDoubleTapListener
private GestureDetector mGestureDetector;
…
mGestureDetector = new GestureDetector(this);
…
mGestureDetector.setOnDoubleTapListener(new MyDoubleTapListener());
…
private class MyDoubleTapListener implements GestureDetector.OnDoubleTapListener {
public boolean onDoubleTapEvent(MotionEvent e) {
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
}
但是如何将它链接到视图呢?这是一个具有一些 View 成员的类。
我真的很感谢你帮助我把这些点联系起来!
Possible Duplicate:
Android - basic gesture detection
I'm trying to have a View sensitive to double taps on an Android. So far, I learned to set up the double tap and know what place to handle the event for action:
API: android.view.GestureDetector.OnDoubleTapListener
private GestureDetector mGestureDetector;
…
mGestureDetector = new GestureDetector(this);
…
mGestureDetector.setOnDoubleTapListener(new MyDoubleTapListener());
…
private class MyDoubleTapListener implements GestureDetector.OnDoubleTapListener {
public boolean onDoubleTapEvent(MotionEvent e) {
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
}
But How do I link it to the View? This is in a class that has a few View members.
I'll really appreciate you helping me connect the dots!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的视图需要实现 onTouchEvent() 方法,并且该方法需要将事件传递给 GestureDetector 的 onTouchEvent() 方法目的。
Your view needs to implement the onTouchEvent() method, and that method needs to pass the event along to the onTouchEvent() method of the GestureDetector object.