PagerAdapter start position

Viewed 87834

I'm using the following example to impliment my viewPager: http://code.google.com/p/viewpagerexample/issues/list

The problem with this example is that I can't figure out how to set my starting position, the default starting position is 0. Basically I wan't to be able to control if there is an available view on its left or the right.

Is there any way to control center's View current position? is there a better way to do it? is it possible to make it circular?

9 Answers

I came across a problem whereby if I set the current item before I set the adapter, the first item I get back will always be the one at position 0.

Make sure you do:

awesomePager.setAdapter(awesomeAdapter);
awesomePager.setCurrentItem(CurrentPosition);

and not:

awesomePager.setCurrentItem(CurrentPosition);
awesomePager.setAdapter(awesomeAdapter);

Using viewPager.setCurrentItem(newPosition); shows to the user the transition from the starting page to the newPosition, to prevent that from happening and show the newPosition directly as if it was the starting point, I added false to the second parameter something like this:

int newPosition = pages.size()-1; // Get last page position

viewPager.setCurrentItem(newPosition, false); // 2nd parameter (false) stands for "smoothScroll"
Related