Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:46:58+00:00 2026-06-11T18:46:58+00:00

I know how to detect a double-click and a two-finger touch event, but how

  • 0

I know how to detect a double-click and a two-finger touch event, but how can I combine these to react so somebody needs to double click with two fingers?

By default, Android has the long press to act as a second form of clicking, but I’m specifically looking for a two-finger double-click.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:46:59+00:00Added an answer on June 11, 2026 at 6:46 pm

    I wanted a simple and reusable interface that listens for two finger double taps and behaves like GestureDetector. So that you could use it like this (all cut & paste runnable code):

    public class Example extends Activity {
        SimpleTwoFingerDoubleTapDetector multiTouchListener = new SimpleTwoFingerDoubleTapDetector() {
            @Override
            public void onTwoFingerDoubleTap() {
                // Do what you want here, I used a Toast for demonstration
                Toast.makeText(Example.this, "Two Finger Double Tap", Toast.LENGTH_SHORT).show();
            }
        };
    
        // Override onCreate() and anything else you want
    
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if(multiTouchListener.onTouchEvent(event))
                return true;
            return super.onTouchEvent(event);
        }
    }
    

    I created SimpleTwoFingerDoubleTapDetector. (It’s a long name, but it is descriptive. You can rename it as anything you want.) Save this new file inside your project or as a library:

    public abstract class SimpleTwoFingerDoubleTapDetector {
        private static final int TIMEOUT = ViewConfiguration.getDoubleTapTimeout() + 100;
        private long mFirstDownTime = 0;
        private boolean mSeparateTouches = false;
        private byte mTwoFingerTapCount = 0;
    
        private void reset(long time) {
            mFirstDownTime = time;
            mSeparateTouches = false;
            mTwoFingerTapCount = 0;
        }
    
        public boolean onTouchEvent(MotionEvent event) {
            switch(event.getActionMasked()) {
            case MotionEvent.ACTION_DOWN:
                if(mFirstDownTime == 0 || event.getEventTime() - mFirstDownTime > TIMEOUT) 
                    reset(event.getDownTime());
                break;
            case MotionEvent.ACTION_POINTER_UP:
                if(event.getPointerCount() == 2)  
                    mTwoFingerTapCount++;
                else 
                    mFirstDownTime = 0;
                break;
            case MotionEvent.ACTION_UP:
                if(!mSeparateTouches)
                    mSeparateTouches = true;
                else if(mTwoFingerTapCount == 2 && event.getEventTime() - mFirstDownTime < TIMEOUT) {
                    onTwoFingerDoubleTap();
                    mFirstDownTime = 0;
                    return true;
                }
            }               
    
            return false;
        }
    
        public abstract void onTwoFingerDoubleTap();
    }
    

    First, a few notes about Android (one-touch) GestureDetector:

    • Android’s onDoubleTap() event uses a standard timeout value from ViewConfiguration. I refer to the same time.
    • They measure the elapsed time from the first tap’s finger-down event to the second tap’s finger-down event, and then broadcast onDoubleTap() and onDoubleTapEvent().
      • onDoubleTap() is fired only when the second tap’s finger-down event occurs.
      • onDoubleTapEvent() is fired for every action by the second tap: down, move, and up.

    A few notes on SimpleTwoFingerDoubleTapDetector:

    • My timeout is measured from the first finger-down event to the last finger-up event to prevent false double-tap notifications. I added a little extra time to the default ViewConfiguration double tap timeout to account for this.
    • Android’s GestureDetector measures slop (how far apart the two taps are). I didn’t see the need for this here, nor did I check the distance between the two fingers on each tap.
    • I only broadcast one event onTwoFingerDoubleTap().

    Final note:
    You can easily change this to behave like an OnTouchListener:

    1. Change SimpleTwoFingerDoubleTapDetector’s definition:

      public abstract class SimpleTwoFingerDoubleTapListener implements OnTouchListener {
      
    2. Add a new class variable:

      private View mFirstView;
      
    3. Change the ACTION_DOWN case:

      case MotionEvent.ACTION_DOWN:
          if(mFirstDownTime == -1 || mFirstView != v || hasTimedOut(event.getEventTime())) {
              mFirstView = v;
              reset(event.getDownTime());
          }
          break;
      
    4. Pass mFirstView inside the ACTION_UP case:

      onTwoFingerDoubleTap(mFirstView);
      
    5. Last, change the onTwoFingerDoubleTap() method to reflect which View was tapped:

      public abstract void onTwoFingerDoubleTap(View v);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that richtextboxes can detect links (like http://www.yahoo.com ) but is there a
I know I can detect flash gaining and losing focus with these callbacks: stg.addEventListener(
I know I can detect a single backspace keypress like this: $(#myelement).bind (keyup, function(event)
I would like to know if it was possible to detect the double-click in
I know a simple URLConnection to google can detect if I am connected to
Does anyone know how can I detect the browser type in css? What I
I would like to know a way can detect on how long the mouse
Does anyone know how I can detect if the headphone jack on a device
Does anyone know if you can detect if headphones are plugged into the iPhone,
Does anyone know how to detect in a OnBeforeUnload event that the server side

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.