Skip to content Skip to sidebar Skip to footer

Catch Double Click On Textview Android

i want to catch double click on textview for that i have used below code but it still not working :( TextView txtOne; @Override protected void onCreate(Bundle savedInstanceState)

Solution 1:

Try following steps.

Step 1

Write following code in your activity.

// initialize the Gesture Detector
gd = newGestureDetector(this,newOnGestureListener() {
    @OverridepublicbooleanonSingleTapUp(MotionEvent e) {
        // TODO Auto-generated method stubreturnfalse;
    }

    @OverridepublicvoidonShowPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @OverridepublicbooleanonScroll(MotionEvent e1, MotionEvent e2, float distanceX,
            float distanceY) {
        // TODO Auto-generated method stubreturnfalse;
    }

    @OverridepublicvoidonLongPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @OverridepublicbooleanonFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        // TODO Auto-generated method stubreturnfalse;
    }

    @OverridepublicbooleanonDown(MotionEvent e) {
        // TODO Auto-generated method stubreturnfalse;
    }
});

// set the on Double tap listener
gd.setOnDoubleTapListener(newOnDoubleTapListener() {
    @OverridepublicbooleanonDoubleTap(MotionEvent e) {
        Toast.makeText(SplashActivity.this,"Double Tap",Toast.LENGTH_LONG).show();
    returnfalse;
    }

    @OverridepublicbooleanonDoubleTapEvent(MotionEvent e) {
        // if the second tap hadn't been released and it's being movedreturnfalse;
    }

    @OverridepublicbooleanonSingleTapConfirmed(MotionEvent e) {
        // TODO Auto-generated method stubreturnfalse;
    }

});

Step 2

Write following code for activity. Here gd will be GestureDetector object.

txt.setOnTouchListener(newView.OnTouchListener() {

        @OverridepublicbooleanonTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            gd.onTouchEvent(event);
            returnfalse;
        }
    });

Solution 2:

Solution 3:

For SimpleGestureDetector, you need to override onDown() and return true to trigger double tap detector.

Whether or not you use GestureDetector.OnGestureListener, it's best practice to implement an onDown() method that returns true. This is because all gestures begin with an onDown() message. If you return false from onDown(), as GestureDetector.SimpleOnGestureListener does by default, the system assumes that you want to ignore the rest of the gesture, and the other methods of GestureDetector.OnGestureListener never get called. This has the potential to cause unexpected problems in your app. The only time you should return false from onDown() is if you truly want to ignore an entire gesture.

Source: http://developer.android.com/training/gestures/detector.html

Solution 4:

This is a good site for performing double click... I used it and worked doubleCLICK

Post a Comment for "Catch Double Click On Textview Android"