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

I want to know the current page position of the ViewPager. I create an adapter and set this adapter to the ViewPager. 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 viewPager.setCurrentItem(1); for setting the first item.

Is there a similar method for getting the current page?


in the latest packages you can also use

vp.getCurrentItem()

or

vp is the viewPager ,

pageListener = new PageListener();
vp.setOnPageChangeListener(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;
        }
    }

There is a method object_of_ViewPager.getCurrentItem() which returns the position of currently Viewed page of view pager