Esempio n. 1
0
  private void notifyDataSetChanged() {
    mTabContainer.removeAllViews();

    PagerAdapter adapter = mViewPager.getAdapter();
    final int count = adapter.getCount();

    if (mSelectedPosition > count) mSelectedPosition = count - 1;

    for (int i = 0; i < count; i++) {
      CharSequence title = adapter.getPageTitle(i);
      if (title == null) title = "NULL";

      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.setOnClickListener(this);
      tv.setTag(i);
      if (mTabRippleStyle > 0) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
          tv.setBackground(new RippleDrawable.Builder(getContext(), mTabRippleStyle).build());
        else
          tv.setBackgroundDrawable(
              new RippleDrawable.Builder(getContext(), mTabRippleStyle).build());
      }

      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);
      }
    }

    setCurrentItem(mSelectedPosition);
    requestLayout();
  }
Esempio n. 2
0
 @Override
 public void onPageSelected(int position) {
   setCurrentItem(position);
   if (mListener != null) mListener.onPageSelected(position);
 }
Esempio n. 3
0
 public void setViewPager(ViewPager view, int initialPosition) {
   setViewPager(view);
   setCurrentItem(initialPosition);
 }