ViewPager viewPager = findViewById(R.id.view_pager); viewPager.setCurrentItem(1);
ViewPager viewPager = findViewById(R.id.view_pager); int lastPageIndex = viewPager.getAdapter().getCount() - 1; viewPager.setCurrentItem(lastPageIndex);In this example, a reference to the ViewPager object is obtained using its resource ID. The last page index is calculated by subtracting 1 from the total count of pages in the ViewPager's adapter. The setCurrentItem method is then called to set the current page of the ViewPager to the last page. The package library for android.support.v4.view ViewPager is "android.support.v4.view".