Mygesturedetector Extends Simpleongesturelistener
I am implementing a MyGestureDetector that extends a SimpleOnGestureListener. I borrowed the class from: http://www.codeshogun.com/blog/tag/view-flipper/ to allow a swipe action i
Solution 1:
I think the problem is that you don't override the OnDown
event. Add this code snippet to your MyGestureDetector
class, and it should be work.
@OverridepublicbooleanonDown(MotionEvent e) {
returntrue;
}
The onDown
event return false by default, and every gesture start with onDown
so your onFling
event will not fire.
Istvan
Solution 2:
Seems like you can now solve this problem with a lot less code using a gesture detector, like this:
import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.GridView;
publicclassScrollingGridViewextendsGridView {
private GestureDetector gestureDetector;
publicScrollingGridView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
publicScrollingGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setupGestureListener();
}
privatevoidsetupGestureListener() {
GestureDetector.SimpleOnGestureListenergestureListener=newGestureDetector.SimpleOnGestureListener() {
@OverridepublicbooleanonScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
scrollBy((int)distanceX, (int)distanceY);
returntrue;
}
};
gestureDetector = newGestureDetector(getContext(), gestureListener);
setOnTouchListener(newOnTouchListener() {
@OverridepublicbooleanonTouch(View view, MotionEvent motionEvent) {
gestureDetector.onTouchEvent(motionEvent);
returntrue;
}
});
}
}
Post a Comment for "Mygesturedetector Extends Simpleongesturelistener"