Change the start page to be displayed in the ViewPagerIndicator

I have implemented ViewPagerIndicator with ActionBarSherlock.

Now I would like to open a specific fragment inside the viewpager after creating the viewpager. Usually you should use setCurrentItem (pageid) or setViewPager (mPager, pageid);

But that doesn't work :( If I would like to open fragment 2 inside the viewpager, the viewpager indicator shows that fragment 2 is shown, but in fact, fragment one (standard) is displayed in the viewpager.

I have the following code:

    public void onCreate(Bundle savedInstanceState) {

        mAdapter = new ColofonFragmentAdapter(getSupportFragmentManager());

        mPager = (ViewPager)findViewById(;
        mIndicator = (TabPageIndicator)findViewById(;
        String page = "";
        page = getIntent().getStringExtra("page");
        int pageid = 0;
        if(page.equals("contact")) { pageid = 0; }
        else if(page.equals("colofon")) { pageid = 1; }
        else if(page.equals("disclaimer")) { pageid = 2; }      

        mIndicator.setViewPager(mPager, pageid); // Doesn't work...
            //mIndicator.setCurrentItem(pageid); // Doesn't work...

class ColofonFragmentAdapter extends FragmentPagerAdapter implements TitleProvider {

        ArrayList<Fragment> fragments = new ArrayList<Fragment>();
        ArrayList<String> titels = new ArrayList<String>();

        public ColofonFragmentAdapter(FragmentManager fm) {
            fragments.add(new LayoutFragment(R.layout.colofon_contactgegevens));
            fragments.add(new LayoutFragment(R.layout.colofon_colofon));
            fragments.add(new LayoutFragment(R.layout.colofon_disclaimer));

        public Fragment getItem(int position) {
            return fragments.get(position);

        public int getCount() {
            return fragments.size();

        public String getTitle(int position) {
            return titels.get(position);


Can you tell me which method should I use to change the start page? Thank!


source to share

1 answer

I think it was a bug caused by setCurrentItem ()

He decided ^^



All Articles