Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect when MotionEvent.ACTION_MOVE is finished

I need to detect in my application when user stop moving across a specific view. I'm creating something similar to marque text in my application which can interact while user is touching the view and moving across it. And I need to start scrolling the view after user lifts his finger. As I notices if I move my finger across the view a few seconds and when I lift my finger the MotionEvent.ACTION_UP is not called. The last event which I capture is ACTION_MOVE . So how can I detect when user lifts his finger after moving across the view a few seconds? Is there some kind of function which can detect that?

Here is the code which I'm using :

txt.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, final MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.e("","event down : "+event.getAction());
                handler.removeCallbacks(runnable);
                break;
            case MotionEvent.ACTION_UP:
                Log.e("","event up : "+event.getAction());
                if(myTimer!=null){
                    myTimer.cancel();
                }
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d("","move");
                // handler.removeCallbacks(runnable);
                checkX();
                break;
        }
        return true;
    }
});

Thanks in advance!

like image 650
Android-Droid Avatar asked Jun 29 '12 07:06

Android-Droid


1 Answers

I think the event may be sending an ACTION_CANCEL action before the gesture is finished. Or, if it drags outside of the view you're checking, it could be ACTION_OUTSIDE.

The best way to confirm/debug this would be to put a Log.d() statement in, print the MotionEvent.getActionMasked() value, and check to see what actions are being called after your ACTION_MOVE event ends.

like image 101
CrepeGoat Avatar answered Sep 17 '22 17:09

CrepeGoat