2

I have this class of a FragmentPagerAdapter.

How could I turn this into a looping ViewPager? So from A - B- C - A(back). I have tried some solutions on this forum, but it doesn't bring me any result.

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();
    }
hectichavana
  • 1,346
  • 11
  • 39
  • 69

0 Answers0