Example #1
0
  public void setCurrentItem(int position) {
    if (mSelectedPosition != position) {
      CheckedTextView tv = getTabView(mSelectedPosition);
      if (tv != null) tv.setChecked(false);
    }

    mSelectedPosition = position;
    CheckedTextView tv = getTabView(mSelectedPosition);
    if (tv != null) tv.setChecked(true);

    animateToTab(position);
  }
Example #2
0
  private void addTemporaryTab() {
    for (int i = 0; i < 3; i++) {
      CharSequence title = null;
      if (i == 0) title = "TAB ONE";
      else if (i == 1) title = "TAB TWO";
      else if (i == 2) title = "TAB THREE";

      CheckedTextView tv = new CheckedTextView(getContext());
      tv.setCheckMarkDrawable(null);
      tv.setText(title);
      tv.setGravity(Gravity.CENTER);
      tv.setTextAppearance(getContext(), mTextApperance);
      tv.setSingleLine(true);
      tv.setEllipsize(TruncateAt.END);
      tv.setTag(i);
      tv.setChecked(i == 0);
      if (mMode == MODE_SCROLL) {
        tv.setPadding(mTabPadding, 0, mTabPadding, 0);
        mTabContainer.addView(
            tv,
            new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
      } else if (mMode == MODE_FIXED) {
        LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT);
        params.weight = 1f;
        mTabContainer.addView(tv, params);
      }
    }
  }