android viewpager, currently active view
-
25-10-2019 - |
문제
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)
제휴하지 않습니다 StackOverflow