sam_k sam_k - 1 year ago 85
Android Question

How do you get the current page number of a ViewPager for Android?

I want to know the current page position of the

. I create an adapter and set this adapter to the
. Now I want to know the current page number or position of the current view, because I want to start some extra events on that particular page.

I used
for setting the first item.

Is there a similar method for getting the current page?

Answer Source

in the latest packages you can also use



vp is the viewPager ,

pageListener = new PageListener();

you have to put a page change listener for your viewPager. There is no method on viewPager to get the current page.

private int currentPage;

    private static class PageListener extends SimpleOnPageChangeListener{
            public void onPageSelected(int position) {
                Log.i(TAG, "page selected " + position);
                   currentPage = position;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download