Question

I am trying to get the currently shown view on screen , I need it to implement the next previous button for viewpager, how can I get currenly shown view on screen, is there any method like getCurrentItemPosition, I have looked into doc and there seems nothing like that which is available

Was it helpful?

Solution

you have to use

viewpager.setOnPageChangeListener(new PageListener());

and keep updating the current page when you get a call to the listener. mCurrentPage will give you the required result.

private static class PageListener extends SimpleOnPageChangeListener{

        public void onPageSelected(int position) {
                 mCurrentPage = position;
            }
}

OTHER TIPS

If you're not doing anything special to ViewPager it should contain child views with same order as in adapter. I'm using following code

View view = mViewPager.getChildAt(mViewPager.getCurrentItem());

Also you can rely on position parameter from method onPageSelected(int position)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top