Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll direction in an OnPageChangeListener

Tags:

android

Is it possible to know the direction of the scroll in the method onPageScrolled of the OnPageChangeListener applied to a ViewPager?

like image 223
Alejandro Pérez Avatar asked Mar 18 '13 03:03

Alejandro Pérez


1 Answers

I've used something like this:

mPager.setOnPageChangeListener(new OnPageChangeListener() {

    int oldPos = mPager.getCurrentItem();

    @Override
    public void onPageScrolled(int position, float arg1, int arg2) {

            if(position > oldPos) {
                 //Moving to the right

            } else if(position < oldPos) {
                 //Moving to the Left
            }

        .
        .
        .

--Edit--

Sorry, changed to onPageScrolled, not onPageSelected..

like image 199
Tim Malseed Avatar answered Sep 30 '22 08:09

Tim Malseed