2

我有这个类的FragmentPagerAdapter

我怎么能把它变成一个循环的 ViewPager?所以从 A - B- C - A(后退)。我在这个论坛上尝试了一些解决方案,但它没有给我带来任何结果。

public class RootCategoriesPagerAdapter extends FragmentPagerAdapter {

    private static final Logger LOG = LoggerFactory.getLogger(RootCategoriesPagerAdapter.class.getSimpleName());

    private final AppDomainResult appDomain;

    public RootCategoriesPagerAdapter(final AppDomainResult appDomain, final FragmentManager fragmentManager) {
        super(fragmentManager);
        this.appDomain = checkNotNull(appDomain, "appDomain");
    }

    @Override
    public int getCount() {
        return appDomain.getRootCategories().size();
    }

    @Override
    public Fragment getItem(final int position) {

        LOG.debug("Creating new Fragment for position {}", position);

        final RootCategoryResult rootCategory = appDomain.getRootCategories().get(position);
        LOG.debug("{}", rootCategory);

        return createRootCategoryFragment(rootCategory);
    }

    private CategoryFragment createRootCategoryFragment(final RootCategoryResult rootCategory) {

        return CategoryFragment.newInstance(rootCategory.getUrlKey(), createViewConfig(rootCategory));
    }

    private static CategoriesAdapterViewConfig createViewConfig(final RootCategoryResult rootCategory) {
        //J-
        return new CategoriesAdapterViewConfig()
                .sourceActivity(SHOP)
                .showTeasers(true)
                .resourceTop(R.drawable.shop_top)
                .resourceMiddle(R.drawable.shop_middle)
                .resourceBottom(R.drawable.shop_bottom)
                .showSearchBar(Optional.fromNullable(rootCategory.getIsHome()).or(false));
        //J+
    }

    @Override
    public CharSequence getPageTitle(final int position) {
        return appDomain.getRootCategories().get(position).getLabel();
    }
4

0 回答 0