anata anata - 1 year ago 87
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 !

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download