2013-05-06 100 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(); 
    } 

回答