Reputation: 12102
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
Upvotes: 2
Views: 2470
Reputation: 1
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)
Upvotes: -1
Reputation: 29121
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;
}
}
Upvotes: 2