コード例 #1
0
  private void populateTabStrip() {
    final PagerAdapter adapter = viewPager.getAdapter();

    for (int i = 0; i < adapter.getCount(); i++) {

      final View tabView =
          (tabProvider == null)
              ? createDefaultTabView(adapter.getPageTitle(i))
              : tabProvider.createTabView(tabStrip, i, adapter);

      if (tabView == null) {
        throw new IllegalStateException("tabView is null.");
      }

      if (distributeEvenly) {
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
        lp.width = 0;
        lp.weight = 1;
      }

      if (internalTabClickListener != null) {
        tabView.setOnClickListener(internalTabClickListener);
      }

      tabStrip.addView(tabView);

      if (i == viewPager.getCurrentItem()) {
        tabView.setSelected(true);
      }
    }
  }
コード例 #2
0
  /** Populate TabStrip tabs. */
  private void populateTabStrip() {
    mNiceTabStrip.removeAllViews();

    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
      View tabView;

      if (mTabProvider != null) {
        tabView = mTabProvider.createTabView(mNiceTabStrip, i, adapter);
      } else {
        tabView = createDefaultTabView(i);
      }

      tabView.setOnClickListener(tabClickListener);

      mNiceTabStrip.addView(tabView);
    }
  }