anata anata - 8 months ago 35
Android Question

Disable next page of ViewPager Android

I have a viewpager with four page. page1,page2,page3,page4.
I want to when at page2,view pager will not be next to page (page3),only previous to page1. How must I do !


You can use the getCount() method in the PagerAdapter to achieve this.

ViewPager viewPager = (ViewPager) findViewById(;
ViewAdapter viewAdapter = new ViewAdapter();

private class ViewAdapter extends PagerAdapter{

    private int count = 4;
    public void setCount(int count) {
        this.count = count;

    public int getCount() {
        return count;
    //other methods