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

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

Introduction

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

Prototype

public abstract int getCount();

Source Link

Document

Return the number of views available.

Usage

From source file:com.cameronvoell.listo.ui_widgets.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 w w .ja  va2s  . co m
        View 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 = tabView.findViewById(mTabViewTextViewId);
        }

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

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

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

        if (TextView.class.isInstance(tabTitleView)) {
            ((TextView) tabTitleView).setText(adapter.getPageTitle(i));
        } else if (ImageView.class.isInstance(tabTitleView) && adapter instanceof TabIconProvider) {
            TabIconProvider mTabIconProvider = (TabIconProvider) adapter;
            tabTitleView.setBackgroundResource(mTabIconProvider.getPageIconResId(i));
        }

        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.example.shayanetan.borrowise2.Views.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();
    tabTitleView = new TextView[adapter.getCount()];

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

        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[i] = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

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

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

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

        tabTitleView[i].setText(adapter.getPageTitle(i));
        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);
        }

        tabTitleView[i].setTextColor(getResources().getColorStateList(bgRes));
        tabTitleView[i].setTextSize(14);
    }
}

From source file:com.hdit.wldemo.widget.SlidingTabLayoutTest.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;/* ww w  .j a  va 2s  .  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;
        }

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

        mItemName = (TabItemName) adapter;
        tabTitleView.setText(mItemName.getTabName(i));
        tabView.setOnClickListener(tabClickListener);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT,
                1.0f);
        tabView.setLayoutParams(layoutParams);
        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.orca.coleherrmann.samplematerial.SlidingTabLayout.java

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;//from www .j a v 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 (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        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);
        }
        int[][] states = new int[][] { new int[] { android.R.attr.state_selected },
                new int[] { android.R.attr.state_focused }, new int[] { android.R.attr.state_pressed },
                new int[] { -android.R.attr.state_selected }, new int[] { -android.R.attr.state_focused },
                new int[] { -android.R.attr.state_pressed } };

        int[] colors = new int[] { Color.parseColor("#0083E5"), Color.parseColor("#0083E5"),
                Color.parseColor("#0083E5"), Color.WHITE, Color.WHITE, Color.WHITE };

        ColorStateList myList = new ColorStateList(states, colors);
        tabTitleView.setTextColor(myList);
        tabTitleView.setTextSize(14);
    }
}

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

@Override
public void notifyDataSetChanged() {
    mTabLayout.removeAllViews();// w w  w .ja  v a  2s.  com
    PagerAdapter adapter = mViewPager.getAdapter();
    IconPagerAdapter iconAdapter = null;
    if (adapter instanceof IconPagerAdapter) {
        iconAdapter = (IconPagerAdapter) adapter;
    }
    final int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        CharSequence title = adapter.getPageTitle(i);
        if (title == null) {
            title = EMPTY_TITLE;
        }
        int iconResId = 0;
        if (iconAdapter != null) {
            iconResId = iconAdapter.getIconResId(i);
        }
        addTab(i, title, iconResId);
    }
    if (mSelectedTabIndex > count) {
        mSelectedTabIndex = count - 1;
    }
    setCurrentItem(mSelectedTabIndex);
    requestLayout();
}

From source file:com.mods.grx.settings.utils.SlidingTabLayout.java

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;/*from  w  ww  .  ja  va2 s  . co 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 (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        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.androidstarterkit.module.widget.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.  j  a  v  a  2s . co m
        View 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 = tabView.findViewById(mTabViewTextViewId);
        }

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

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

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

        if (TextView.class.isInstance(tabTitleView)) {
            ((TextView) tabTitleView).setText(adapter.getPageTitle(i));
        } else if (ImageView.class.isInstance(tabTitleView) && adapter instanceof TabIconProvider) {
            TabIconProvider mTabIconProvider = (TabIconProvider) adapter;
            tabTitleView.setBackgroundResource(mTabIconProvider.getPageIconResId(i));
        }

        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.crazy.toutiaonews.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  ww. java  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);
            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);

        // ===========================  ============================
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT,
                1.0f);
        tabView.setLayoutParams(layoutParams);
        // ===============================  =========

        mTabStrip.addView(tabView);
    }
}

From source file:com.tech.frontier.widgets.AutoScrollViewPager.java

/**
 * <ul>/*  w  w w . jav a  2s . c  o  m*/
 * if stopScrollWhenTouch is true
 * <li>if event is down, stop auto scroll.</li>
 * <li>if event is up, start auto scroll again.</li>
 * </ul>
 */
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    int action = MotionEventCompat.getActionMasked(ev);

    if (stopScrollWhenTouch) {
        if ((action == MotionEvent.ACTION_DOWN) && isAutoScroll) {
            isStopByTouch = true;
            stopAutoScroll();
        } else if (ev.getAction() == MotionEvent.ACTION_UP && isStopByTouch) {
            startAutoScroll();
        }
    }

    if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT || slideBorderMode == SLIDE_BORDER_MODE_CYCLE) {
        touchX = ev.getX();
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            downX = touchX;
        }
        int currentItem = getCurrentItem();
        PagerAdapter adapter = getAdapter();
        int pageCount = adapter == null ? 0 : adapter.getCount();
        /**
         * current index is first one and slide to right or current index is
         * last one and slide to left.<br/>
         * if slide border mode is to parent, then
         * requestDisallowInterceptTouchEvent false.<br/>
         * else scroll to last one when current item is first one, scroll to
         * first one when current item is last one.
         */
        if ((currentItem == 0 && downX <= touchX) || (currentItem == pageCount - 1 && downX >= touchX)) {
            if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT) {
                getParent().requestDisallowInterceptTouchEvent(false);
            } else {
                if (pageCount > 1) {
                    setCurrentItem(pageCount - currentItem - 1, isBorderAnimation);
                }
                getParent().requestDisallowInterceptTouchEvent(true);
            }
            return super.dispatchTouchEvent(ev);
        }
    }
    getParent().requestDisallowInterceptTouchEvent(true);

    return super.dispatchTouchEvent(ev);
}

From source file:com.zeferino.bruno.pap.view.MovieDetailsSlidingTabLayout.java

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;//from  w ww.jav a2 s  . co  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;
        }

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

        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.weight = 1;
        tabView.setLayoutParams(lp);

        mTabStrip.addView(tabView);

        tabTitleView.setTextColor(getResources().getColorStateList(R.color.tabselector));

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