Search in sources :

Example 1 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project cw-omnibus by commonsguy.

the class TabPageIndicator method setViewPager.

@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    final PagerAdapter adapter = view.getAdapter();
    if (adapter == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    view.setOnPageChangeListener(this);
    notifyDataSetChanged();
}
Also used : PagerAdapter(android.support.v4.view.PagerAdapter)

Example 2 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project cw-omnibus by commonsguy.

the class TabPageIndicator method notifyDataSetChanged.

public void notifyDataSetChanged() {
    mTabLayout.removeAllViews();
    PagerAdapter adapter = mViewPager.getAdapter();
    final int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        CharSequence title = adapter.getPageTitle(i);
        if (title == null) {
            title = EMPTY_TITLE;
        }
        addTab(title, i);
    }
    if (mSelectedTabIndex > count) {
        mSelectedTabIndex = count - 1;
    }
    setCurrentItem(mSelectedTabIndex);
    requestLayout();
}
Also used : PagerAdapter(android.support.v4.view.PagerAdapter)

Example 3 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project SeriesGuide by UweTrottmann.

the class SlidingTabLayout method populateTabStrip.

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final 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);
    }
}
Also used : TextView(android.widget.TextView) HorizontalScrollView(android.widget.HorizontalScrollView) TextView(android.widget.TextView) View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter)

Example 4 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project Carbon by ZieIony.

the class PagerTabStrip method initTabs.

private void initTabs() {
    content.removeAllViews();
    if (viewPager == null)
        return;
    final PagerAdapter adapter = viewPager.getAdapter();
    if (viewPager.getAdapter() == null)
        return;
    if (tabBuilder == null) {
        tabBuilder = position -> {
            View tab = inflate(getContext(), R.layout.carbon_tab, null);
            ((TextView) tab.findViewById(R.id.carbon_tabText)).setText(getViewPager().getAdapter().getPageTitle(position).toString().toUpperCase());
            return tab;
        };
    }
    for (int i = 0; i < adapter.getCount(); i++) {
        View tab = tabBuilder.getView(i);
        content.addView(tab, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f));
        tab.setSelected(i == 0);
        final int finalI = i;
        tab.setOnClickListener(__ -> viewPager.setCurrentItem(finalI));
    }
}
Also used : View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter) Paint(android.graphics.Paint) LinearLayout(android.widget.LinearLayout)

Example 5 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project UltimateAndroid by cymcsg.

the class MaterialTabTextActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.material_tab_text_activity_main);
    Toolbar toolbar = (Toolbar) this.findViewById(R.id.toolbar);
    this.setSupportActionBar(toolbar);
    tabHost = (MaterialTabHost) this.findViewById(R.id.tabHost);
    pager = (ViewPager) this.findViewById(R.id.pager);
    // init view pager
    adapter = new ViewPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(adapter);
    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            // when user do a swipe the selected tab change
            tabHost.setSelectedNavigationItem(position);
        }
    });
    // insert all tabs from pagerAdapter data
    for (int i = 0; i < adapter.getCount(); i++) {
        tabHost.addTab(tabHost.newTab().setText(adapter.getPageTitle(i)).setTabListener(this));
    }
}
Also used : ViewPager(android.support.v4.view.ViewPager) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

PagerAdapter (android.support.v4.view.PagerAdapter)142 ViewPager (android.support.v4.view.ViewPager)77 View (android.view.View)72 TextView (android.widget.TextView)55 ViewGroup (android.view.ViewGroup)26 HorizontalScrollView (android.widget.HorizontalScrollView)26 TabLayout (android.support.design.widget.TabLayout)23 Toolbar (android.support.v7.widget.Toolbar)18 LinearLayout (android.widget.LinearLayout)18 ImageView (android.widget.ImageView)16 ArrayList (java.util.ArrayList)15 Fragment (android.support.v4.app.Fragment)14 FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)14 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)13 Bundle (android.os.Bundle)12 Intent (android.content.Intent)9 LayoutInflater (android.view.LayoutInflater)9 RecyclerView (android.support.v7.widget.RecyclerView)8 SuppressLint (android.annotation.SuppressLint)7 MenuItem (android.view.MenuItem)7