문제

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

도움이 되었습니까?

해결책

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;
            }
}

다른 팁

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top