I have tried to extend GestureDetector.SimpleOnGestureListener
class to detect gestures on Dialog
, it worked for me but it does not detect single tap, on down, scroll, etc. events on any button, checkbox, radio button in the dialog, it's only detecting these events while touching the white area inside dialog. Anyone knows how can I detect the gestures on various buttons and other control in a dialog?
Here is the code snippet of my dialog and gesture listener:
public class SimpleDialog extends Dialog {
private GestureDetector gestureDetector;
public SimpleDialog(Context context) {
super(context);
gestureDetector = new GestureDetector(context, new MyGestureDetector());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_simple);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
private class MyGestureDetector extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
System.out.println( "touch event onFling()");
return false;
}
MyGestureDetector() {
super();
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
System.out.print("touch event onSingleTapUp()");
return super.onSingleTapUp(e);
}
@Override
public void onLongPress(MotionEvent e) {
super.onLongPress(e);
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
System.out.println("touch event onScroll()");
return super.onScroll(e1, e2, distanceX, distanceY);
}
@Override
public void onShowPress(MotionEvent e) {
super.onShowPress(e);
}
@Override
public boolean onDown(MotionEvent e) {
System.out.println("touch event onDown()");
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
return super.onDoubleTap(e);
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return super.onDoubleTapEvent(e);
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return super.onSingleTapConfirmed(e);
}
@Override
public boolean onContextClick(MotionEvent e) {
return super.onContextClick(e);
}
}
}