I need to detect different gestures on more then one views. My views need to be able to receive Tap, Double Tap and Drag Events. I tried the Gesture Detector but my implementation shows me only global gesture events and I can't connect these events to a specific view.
in my activity.onCreate:
dthandler = new DoubleTapHandler();
mDetector = new GestureDetector(this,dthandler);
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Log.d("myLog","touch");
mDetector.onTouchEvent(event);
return false;
}
};
in my activity I override the dispatchTouch function:
@Override
public boolean dispatchTouchEvent(MotionEvent me){
this.mDetector.onTouchEvent(me);
return super.dispatchTouchEvent(me);
}
this is how I try to connect the touchevent with my views:
prod.setOnTouchListener(this.gestureListener);
my DoubleTapHandler:
public class DoubleTapHandler implements OnDoubleTapListener, OnGestureListener {
private ProductView relatedView;
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
Log.d("myLog", "onDoubleTapEvent");
Log.d("myLog",""+e.getSource());
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
Log.d("myLog", "onDoubleTap"+relatedView);
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Log.d("myLog", "singletap");
return false;
}
}
Anyone has an advice? Thanks!
To make it working, attach gestures directly to each View, and you can have different implementations then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With