anata anata - 4 months ago 12
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

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

ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
ViewAdapter viewAdapter = new ViewAdapter();
viewAdapter.setCount(2);
viewPager.setAdapter(viewAdapter);


private class ViewAdapter extends PagerAdapter{

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

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