2013-05-06 95 views
1

我有这个类的FragmentPagerAdapter做一个循环ViewPager

我怎么能把它变成循环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(); 
    } 

回答