Java – mViewPager.getCurrentItem() does not return the correct position of the first and last pagers

mViewPager.getCurrentItem() does not return the correct position of the first and last pagers… here is a solution to the problem.

mViewPager.getCurrentItem() does not return the correct position of the first and last pagers

I’m trying to get the page number of the View pager, and I’ve come across a lot of Stackoverflow Q&A and they all say to use

currentposition = mViewPager.getCurrentItem();

But this method does not work for the first and last pagers.

How to solve this problem?

Thanks in advance

Solution

This Method use:-

mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

@Override
            public void onPageSelected(int pos) {

int  currentposition = pos;

 Log.e("Current Postion", "" + pos);

}

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

}

@Override
            public void onPageScrollStateChanged(int arg0) {

}
        });

Related Problems and Solutions