Example usage for android.support.v4.view PagerAdapter getPageTitle

List of usage examples for android.support.v4.view PagerAdapter getPageTitle

Introduction

In this page you can find the example usage for android.support.v4.view PagerAdapter getPageTitle.

Prototype

public CharSequence getPageTitle(int position) 

Source Link

Document

This method may be called by the ViewPager to obtain a title string to describe the specified page.

Usage

From source file:com.example.sdave.footballscore.SlidingTabs.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/* w w w  . j  a  v a  2  s .  c  om*/
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }
        tabTitleView.setTextColor(getResources().getColor(R.color.WHITE));

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
    }
}

From source file:de.mein_fischfang.view.SlidingTabLayout.java

/**
 * populateTabStrip// ww w .  ja  v a 2 s .  c  om
 */
private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

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

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
    }
}

From source file:com.matescorp.parkinggo.view.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*from w ww  .j  av a  2 s. co  m*/
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

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

        tabTitleView.setText(adapter.getPageTitle(i));
        tabTitleView.setTextColor(Color.WHITE);
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}

From source file:com.oldfeel.view.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;// w w  w .  jav  a2  s .  c  o  m
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (i == 0) {
            tabView.setSelected(true);
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
    }
}

From source file:com.vgaw.androidtest.view.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*from  ww  w. ja  va 2s. c  o m*/
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            if (mTabViewTextViewId != 0) {
                tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
            }
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);

    }
    mTabStrip.check(mTabStrip.getChildAt(0).getId());
}

From source file:dk.dr.radio.diverse.PagerSlidingTabStrip.java

public void notifyDataSetChanged() {

      tabsContainer.removeAllViews();//  ww  w  .  j  a  v  a2 s .  c  o m
      PagerAdapter adapter = pager.getAdapter();

      tabCount = adapter.getCount();

      for (int i = 0; i < tabCount; i++) {

          if (adapter instanceof IconTabProvider) {
              IconTabProvider ipa = ((IconTabProvider) adapter);
              if (TEKST_DER_FADER_OVER_I_IKONER) {
                  int resId = ipa.getPageIconResId(i);
                  if (resId != 0)
                      addIconTabBdeTekstOgBillede(i, resId, ipa.getPageContentDescription(i));
                  else
                      addTextTab(i, adapter.getPageTitle(i).toString());
              } else {
                  addIconTab(i, ipa.getPageIconResId(i), ipa.getPageContentDescription(i));
              }
          } else {
              addTextTab(i, adapter.getPageTitle(i).toString());
          }

      }

      updateTabStyles();

      getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

          @SuppressWarnings("deprecation")
          @SuppressLint("NewApi")
          @Override
          public void onGlobalLayout() {

              if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                  getViewTreeObserver().removeGlobalOnLayoutListener(this);
              } else {
                  getViewTreeObserver().removeOnGlobalLayoutListener(this);
              }

              currentPosition = pager.getCurrentItem();
              scrollToChild(currentPosition, 0);
          }
      });

  }

From source file:com.sudeep23.lollipoptabs.slidingtab.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    removeOldSelection(); // add those two lines
    oldSelection = null;/*from   w ww  .  j a  v a  2 s  . com*/

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

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
    }
}

From source file:com.benefit.buy.library.viewpagerindicator.PagerSlidingTabStrip.java

public void notifyDataSetChanged() {
    tabsContainer.removeAllViews();//from w ww  . j a  v a2 s.c  o m
    tabCount = pager.getAdapter().getCount();
    PagerAdapter adapter = pager.getAdapter();
    IconPagerAdapter iconAdapter = null;
    if (adapter instanceof IconPagerAdapter) {
        iconAdapter = (IconPagerAdapter) adapter;
        for (int i = 0; i < tabCount; i++) {
            int iconResId = 0;
            int iconResclickId = 0;
            int count = 0;
            if (iconAdapter != null) {
                iconResId = iconAdapter.getIconResId(i);
                iconResclickId = iconAdapter.getIconResclickId(i);
                count = iconAdapter.getItemHint(i);
            }
            addIconTab(i, adapter.getPageTitle(i).toString(), iconResId, iconResclickId, count);
        }
    } else {
        for (int i = 0; i < tabCount; i++) {
            addTextTab(i, pager.getAdapter().getPageTitle(i).toString());
        }
    }
    updateTabStyles();
    getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            getViewTreeObserver().removeGlobalOnLayoutListener(this);
            currentPosition = pager.getCurrentItem();
            scrollToChild(currentPosition, 0);
        }
    });
}

From source file:acn.android.framework.view.helper.SlidingTabLayout.java

private void populateTabStrip(float tabTitleSize, ColorStateList textColorStateList) {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/* ww w .j  a  va 2  s . co  m*/
        AcnTextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (AcnTextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && AcnTextView.class.isInstance(tabView)) {
            tabTitleView = (AcnTextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        ////////TAB CUSTOMIZATIONS///////
        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }

        tabTitleView.setHorizontalFadingEdgeEnabled(true);
        if (!TextUtils.isEmpty(Config.appFont))
            tabTitleView
                    .setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/" + Config.appFont));
        tabTitleView.setTextColor(textColorStateList);
        tabTitleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTitleSize);

        /*WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        int widthInPx = Math.min(display.getHeight(), display.getWidth()); //ACCORDING TO MINIMUM WIDTH-ED SIDE
        tabTitleView.setLayoutParams(new LinearLayout.LayoutParams(widthInPx / 3, LayoutParams.WRAP_CONTENT));*/
        /////////////////////////////////

        mTabStrip.addView(tabView);
    }
}

From source file:com.halzhang.android.library.BottomTabIndicator.java

private void setupChildView() {
    if (mViewPager != null && mViewPager.getAdapter() != null) {
        removeAllViews();/*from  ww  w  .  j  a v a2  s .  c o m*/
        PagerAdapter adapter = mViewPager.getAdapter();
        int count = adapter.getCount();
        if (count < 1) {
            throw new RuntimeException("The adapter's count must be > 0");
        }
        int[] tabViewIds = getTabViewId(adapter);
        if (tabViewIds == null) {
            mTabViewIds = new int[count];
            for (int i = 0; i < count; i++) {
                mTabViewIds[i] = i;
            }
        } else {
            mTabViewIds = tabViewIds;
            //TODO ? count 
        }
        for (int i = 0; i < count; i++) {
            RadioButton radioButton = (RadioButton) LayoutInflater.from(getContext())
                    .inflate(R.layout.tab_indicator, null);
            int pageIcon = getPageIcon(adapter, i);
            if (pageIcon > 0) {
                radioButton.setCompoundDrawablesWithIntrinsicBounds(null, getDrawable(getContext(), pageIcon),
                        null, null);
            }
            radioButton.setText(adapter.getPageTitle(i));
            radioButton.setId(mTabViewIds[i]);
            LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT, 1);
            addView(radioButton, layoutParams);
        }
    }
}