I have a problem with detecting fling gestures in my app. My layout consists of a GridView, couple of TextViews and buttons.
I implemented OnGestureListener:
public class MyActivity extends Activity implements OnGestureListener{
private GestureDetector myGesture ;
then in OnCreate:
myGesture = new GestureDetector(this);
and Overridden methods:
@Override
public boolean onTouchEvent(MotionEvent event){
return myGesture.onTouchEvent(event);
}
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
//right to left fling
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
//left to right fling
}
} catch (Exception e) {
// nothing
}
return false;
}
And this actually works great, but NOT on the GridView. Wherever outside the GridView I perform the fling, it works. On the GridView - there's absolutely no reaction. I have literally no idea, what to do about it, so thanks for any help in advance.
I actually found another solution, because the way I tried to do it simply didn't work and nobody knows why. I used GestureOverlayView instead, and it works great. Just had to add two swipe gestures to the gesture library.