android

How to listen to double tap on a view in android?

final GestureDetector gd = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener(){


       //here is the method for double tap


        @Override
        public boolean onDoubleTap(MotionEvent e) {

            //your action here for double tap e.g.
            //Log.d("OnDoubleTapListener", "onDoubleTap");

            return true;
        }

        @Override
        public void onLongPress(MotionEvent e) {
            super.onLongPress(e);

        }

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

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }


    });

//here yourView is the View on which you want to set the double tap action

yourView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            return gd.onTouchEvent(event);
        }
    });

Put this piece of code on the activity or adapter where you want to set the double tap action on your view.

Similar Posts:

    None Found

Leave a Reply

Your email address will not be published. Required fields are marked *