The other answers can solve the question,maybe they work good,but I don't think those are good solutions.
Because we should deal with the event in a single moudle,so that we can be esaier to maintain or expand the code.
(By the way, don not use onFilng()
,if your finger move slowly on the screen,onFilng()
wouldn't work)
So,my solution is rewriting the GestureDetector:
public class ModifyGestureDetector extends GestureDetector {
MyGestureListener myGestureListener;
public ModifyGestureDetector(Context context, OnGestureListener listener) {
super(context, listener);
init(listener);
}
void init(OnGestureListener listener){
if (listener instanceof MyGestureListener){
myGestureListener = (MyGestureListener) listener;
}
}
//u can write something more complex as long as u need
@Override
public boolean onTouchEvent(MotionEvent ev) {
if(ev.getAction() == MotionEvent.ACTION_UP
&& myGestureListener != null){
myGestureListener.onUp(ev);
}
return super.onTouchEvent(ev);
}
public interface MyGestureListener{
public void onUp(MotionEvent ev);
}
}
And the listener:
public class MyGestureListener extends GestureDetector.SimpleOnGestureListener
implements ModifyGestureDetector.MyGestureListener {
@Override
public void onUp(MotionEvent ev) {
//do what u want
}
}
: )
onSingleTapUp
inGestureListener
that might be what you are looking for. It is fired on a complete tap, though, not swiping. For that you could just process the "raw"onTouchEvent
of view/activity without passing it toGestureDetector
. – XiononFling
, except that you don't get the MOVE events. If you need them, I guess your only option is to handleonTouchEvent
directly. – Xion