[JAVA] How to determine whether you flicked left or right in PagerView

/ ** Coordinates before Touch * / private boolean mIsPagerViewTouchDown = false;

    pager.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            float touchX = event.getX();

            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    mPreviousTouchPointX = touchX;
                    break;
                case MotionEvent.ACTION_UP:
                    float dx = touchX - mPreviousTouchPointX;

// Compare the touch coordinates at TouchDown and the coordinates at TouchUp to determine which one you flicked if ((Math.abs(dx) > 1)) { if (dx > 0) { Log.d (MainActivity.class.getSimpleName (), "flick right" + dx); } else { Log.d (MainActivity.class.getSimpleName (), "Flick left" + dx); } } break; default: break; }

            mPreviousTouchPointX = touchX;
            return false;
        }
    });

Recommended Posts

How to determine whether you flicked left or right in PagerView
How to convert A to a and a to A using AND and OR in Java
How to handle items in GSON that do not know whether they are single or array
[Ruby] How to count even or odd numbers in an array
[Rails / Routing] How to refer to the controller in the directory you created
[jOOQ] How to CASE WHEN in the WHERE / AND / OR clause
How to set an image in the drawable Left / Right of a button using an icon font (Iconics)
How to use Lombok in Spring
How to find May'n in XPath
How to hide scrollbars in WebView
How to run JUnit in Eclipse
How to iterate infinitely in Ruby
[Rails] How to write in Japanese
How to run Ant in Gradle
How to use binding.pry [53 days left]
How to master programming in 3 months
How to learn JAVA in 7 days
How to get parameters in Spark
How to install Bootstrap in Ruby
How to use InjectorHolder in OpenAM
How to introduce jQuery in Rails 6
How to use classes in Java?
How to name variables in Java
How to set Lombok in Eclipse
How to concatenate strings in java
How to install Swiper in Rails
How to develop from VScode in a remote destination environment or a remote destination container environment
How to test private methods with arrays or variadic arguments in JUnit
(Limited to Java 7 or later) I want you to compare objects in Objects.equals