如何使用OnTouchListener捕获Android中的双击事件 [英] How to catch double tap events in Android using OnTouchListener

查看:130
本文介绍了如何使用OnTouchListener捕获Android中的双击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OnTouchListener捕获双击事件.我想我将为motionEvent.ACTION_DOWN设置一个长整数,为第二个motionEvent.ACTION_DOWN设置一个不同的长整数,并测量它们两个之间的时间,然后对其进行处理.但是,我很难弄清楚该如何处理.我正在使用开关盒来拾取多点触摸事件,所以我宁愿不尝试重新构建所有这些以实现GestureDetector(不幸的是,不可能同时实现ontouchlistener和Gesturedetector).任何想法都会有很大帮助:

I am trying to catch double-tap events using OnTouchListener. I figure I would set a long for motionEvent.ACTION_DOWN, and a different long for a second motionEvent.ACTION_DOWN and measure the time between the two of them and then do something with it. However, I am having a hard time figuring out exactly how to approach this. I am using switch cases to pick up multitouch events, so I'd rather not try and retool this all to implement GestureDetector (and unfortunately it is impossible to implement both ontouchlistener and Gesturedetector simultaneously). Any ideas would help greatly:

i.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {


                  ImageView i = (ImageView) v;

                  switch (event.getAction() & MotionEvent.ACTION_MASK) {


                  case MotionEvent.ACTION_DOWN:
                      long firstTouch = System.currentTimeMillis();
                     ///how to grab the second action_down????

                     break;

推荐答案

我之前解决了这个问题.它涉及使用处理程序来等待一定的时间来等待第二次单击:

I addressed this problem earlier. It involves using a Handler to wait a certain amount of time to wait for the second click: How can I create a Single Click Event and Double Click Event when the Menu Button is pressed?

这篇关于如何使用OnTouchListener捕获Android中的双击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆