Catch Double Click On Textview Android
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 anonDown()
method that returnstrue
. This is because all gestures begin with anonDown()
message. If you returnfalse
fromonDown()
, asGestureDetector.SimpleOnGestureListener
does by default, the system assumes that you want to ignore the rest of the gesture, and the other methods ofGestureDetector.OnGestureListener
never get called. This has the potential to cause unexpected problems in your app. The only time you should returnfalse
fromonDown()
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"