Eddie
Eddie

Reputation: 77

What is the difference between onDoubleTap listener and onDoubleTapEvent listener

I am pretty new in Android, and recently learned about gestures!

What is the difference between 2 of these methods?

@Override
public boolean onDoubleTap(MotionEvent e) {
    return false;
}

And this one

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
    return false;
}

They seem to do the same thing. Which one do you use, and what is the difference

Upvotes: 5

Views: 5614

Answers (1)

Charuka Silva
Charuka Silva

Reputation: 13153

simple answer will be

 boolean onDoubleTap (MotionEvent e) - 

Notified when a double-tap occurs.

you can Notifi when a double-tap happens and param motionEvent is forThe down motion event of the first tap.

  boolean onDoubleTapEvent (MotionEvent e)` -

Notified when an event within a double-tap gesture occurs

you can Notifi an event within a double-tap gesture occurs, including the down, move, and up events and and param motionEvent is for the The motion event

so with doubleTapEvent you can get additional tab gestures along with the tap

have a look --> https://stackoverflow.com/a/19629851/5188159 this might helpful for your touch gestures

further more try to understand what happens here with this example

//initialize the Gesture Detector  
        gd = new GestureDetector(this);  

        //set the on Double tap listener  
        gd.setOnDoubleTapListener(new OnDoubleTapListener()  
        {  
            @Override  
            public boolean onDoubleTap(MotionEvent e)  
            {  
                //set text color to green  
                tvTap.setTextColor(0xff00ff00);  
                //print a confirmation message  
                tvTap.setText("The screen has been double tapped.");  
                return false;  
            }  

            @Override  
            public boolean onDoubleTapEvent(MotionEvent e)  
            {  
                //if the second tap hadn't been released and it's being moved  
                if(e.getAction() == MotionEvent.ACTION_MOVE)  
                {  
                    //set text to blue  
                    tvTapEvent.setTextColor(0xff0000ff);  
                    //print a confirmation message and the position  
                    tvTapEvent.setText("Double tap with movement. Position:\n"  
                            + "X:" + Float.toString(e.getRawX()) +  
                            "\nY: " + Float.toString(e.getRawY()));  
                }  
                else if(e.getAction() == MotionEvent.ACTION_UP)//user released the screen  
                {  
                    tvTapEvent.setText("");  
                }  
                return false;  
            }  

            @Override  
            public boolean onSingleTapConfirmed(MotionEvent e)  
            {  
                //set text color to red  
                tvTap.setTextColor(0xffff0000);  
                //print a confirmation message and the tap position  
                tvTap.setText("Double tap failed. Please try again.");  
                return false;  
            }  
        });

Upvotes: 4

Related Questions