I need to define different gestures on more than one view. My submissions should be able to receive Tap, Double Tap and Drag Events. I tried a gesture detector, but my implementation shows me only global gesture events, and I can’t connect these events to a specific view.
in my .onCreate activity:
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 work, 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 touchhevent 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 have any advice? Thank!
source
share