Example #1
0
 public void setViewPager(ExtendedViewPager pager) {
   final PagerAdapter adapter = pager.getAdapter();
   if (adapter == null) return;
   // throw new IllegalStateException("ViewPager has not been bound.");
   if (!(adapter instanceof TitleProvider))
     throw new IllegalStateException(
         "ViewPager adapter must implement TitleProvider to be used with TitlePageIndicator.");
   mViewPager = pager;
   pager.setOnPageChangeListener(this);
   notifyDataSetChanged();
 }
Example #2
0
 public void notifyDataSetChanged() {
   if (mTabLayout == null || mViewPager == null) return;
   mTabLayout.removeAllViews();
   mAdapter = (TitleProvider) mViewPager.getAdapter();
   if (mAdapter == null) return;
   final int count = ((PagerAdapter) mAdapter).getCount();
   for (int i = 0; i < count; i++) {
     final String title = mAdapter.getTitle(i);
     final Drawable icon = mAdapter.getIcon(i);
     if (title != null && icon != null) {
       addTab(title, icon, i);
     } else if (title == null && icon != null) {
       addTab(icon, i);
     } else if (title != null && icon == null) {
       addTab(title, i);
     }
   }
   if (mSelectedTabIndex > count) {
     mSelectedTabIndex = count - 1;
   }
   setCurrentItem(mSelectedTabIndex);
   requestLayout();
 }