使用SectionsPagerAdapter android

Aug*_*cis 2 android android-fragments

我有一个sectionsPagerAdapter,用作ViewPager的适配器.

    mSectionsPagerAdapter = new SectionsPagerAdapter(
            getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
Run Code Online (Sandbox Code Playgroud)

我有3个片段,我想在点击一个按钮时切换2个片段?

小智 7

我猜你在使用ADT创建一个新活动并指定带有标签的导航类型时会自动生成你的SectionsPagerAdapter.如果是这种情况,那么您的SectionsPagerAdapter正在扩展FragmentPagerAdapter,其文档位于此处.

如果您真的想将ViewPager用于所讨论的内容,请查看指向Android开发人员参考的链接.听起来,就像你想要做的更类似于本Q/A中讨论的内容.也许你可以详细说明你想要完成的事情?