Skip to content Skip to sidebar Skip to footer

How To Find The "last Page" In A View Pager. Or The Total 'number' Of Views. Android Development

Thank you for your help in advanced. And sorry if this is a very silly question, but I cannot find it elsewhere. What I want, is basically, to determine the total amount of pages

Solution 1:

You should be using ViewPager.getAdapter().getCount() The getAdapter() method returns the object that supplies the pages for the ViewPager.

Solution 2:

in OnCreate():

 ViewPager vp = (ViewPager) findViewById(R.id.viewPager);


System.out.println(vp.getChildCount());

The following code is working fine for me:

publicclassViewFlipperMainActivityextendsActivity {
    private ViewFlipper viewFlipper;
    privatefloat lastX;

    @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE); 
        setContentView(R.layout.help_flipper);
        viewFlipper = (ViewFlipper) findViewById(R.id.view_flipper);    
        System.out.println(viewFlipper.getChildCount());
    }
}

Solution 3:

You set the setOffscreenPageLimit when creates a ViewPager.

int cont = list.size()
    mViewPager.setOffscreenPageLimit(cont);

Then you can access by

mViewPager.getOffscreenPageLimit()

Post a Comment for "How To Find The "last Page" In A View Pager. Or The Total 'number' Of Views. Android Development"