Search in sources :

Example 86 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project cube-sdk by liaohuqiu.

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 87 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project cube-sdk by liaohuqiu.

the class TabPageIndicator method notifyDataSetChanged.

public void notifyDataSetChanged() {
    mTabLayout.removeAllViews();
    PagerAdapter adapter = mViewPager.getAdapter();
    final int count = adapter.getCount();
    LayoutInflater layoutInflater = LayoutInflater.from(this.getContext());
    for (int i = 0; i < count; i++) {
        ViewHolderBase viewHolder = mViewHolderCreator.createViewHolder();
        viewHolder.setIndex(i);
        View view = viewHolder.createView(layoutInflater, i);
        view.setFocusable(true);
        view.setOnClickListener(mTabClickListener);
        view.setTag(viewHolder);
        if (view.getLayoutParams() == null) {
            mTabLayout.addView(view, new LinearLayout.LayoutParams(WRAP_CONTENT, MATCH_PARENT));
        } else {
            mTabLayout.addView(view);
        }
    }
    mSelectedTabIndex = mViewPager.getCurrentItem();
    updateTab(mSelectedTabIndex);
    requestLayout();
}
Also used : LayoutInflater(android.view.LayoutInflater) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter) LinearLayout(android.widget.LinearLayout)

Example 88 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project subsampling-scale-image-view by davemorrissey.

the class ViewPagerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(layout.view_pager);
    getActionBar().setTitle("View pager gallery");
    getActionBar().setDisplayHomeAsUpEnabled(true);
    PagerAdapter pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
    page = (ViewPager) findViewById(R.id.pager);
    page.setAdapter(pagerAdapter);
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) PagerAdapter(android.support.v4.view.PagerAdapter)

Example 89 with PagerAdapter

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

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;
        }
        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);
        }
    }
}
Also used : TextView(android.widget.TextView) HorizontalScrollView(android.widget.HorizontalScrollView) TextView(android.widget.TextView) View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter) LinearLayout(android.widget.LinearLayout)

Example 90 with PagerAdapter

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

the class ViewPager method setAdapter.

/**
     * Set a PagerAdapter that will supply views for this pager as needed.
     *
     * @param adapter Adapter to use
     */
public void setAdapter(PagerAdapter adapter) {
    if (mAdapter != null) {
        mAdapter.unregisterDataSetObserver(mObserver);
        mAdapter.startUpdate(this);
        for (int i = 0; i < mItems.size(); i++) {
            final ItemInfo ii = mItems.get(i);
            mAdapter.destroyItem(this, ii.position, ii.object);
        }
        mAdapter.finishUpdate(this);
        mItems.clear();
        removeNonDecorViews();
        mCurItem = 0;
        scrollTo(0, 0);
    }
    final PagerAdapter oldAdapter = mAdapter;
    mAdapter = adapter;
    mExpectedAdapterCount = 0;
    if (mAdapter != null) {
        if (mObserver == null) {
            mObserver = new PagerObserver();
        }
        mAdapter.registerDataSetObserver(mObserver);
        mPopulatePending = false;
        final boolean wasFirstLayout = mFirstLayout;
        mFirstLayout = true;
        mExpectedAdapterCount = mAdapter.getCount();
        if (mRestoredCurItem >= 0) {
            mAdapter.restoreState(mRestoredAdapterState, mRestoredClassLoader);
            setCurrentItemInternal(mRestoredCurItem, false, true);
            mRestoredCurItem = -1;
            mRestoredAdapterState = null;
            mRestoredClassLoader = null;
        } else if (!wasFirstLayout) {
            populate();
        } else {
            requestLayout();
        }
    }
    if (mAdapterChangeListener != null && oldAdapter != adapter) {
        mAdapterChangeListener.onAdapterChanged(oldAdapter, adapter);
    }
}
Also used : PagerAdapter(android.support.v4.view.PagerAdapter)

Aggregations

PagerAdapter (android.support.v4.view.PagerAdapter)111 View (android.view.View)49 ViewPager (android.support.v4.view.ViewPager)44 TextView (android.widget.TextView)33 ViewGroup (android.view.ViewGroup)19 HorizontalScrollView (android.widget.HorizontalScrollView)19 LinearLayout (android.widget.LinearLayout)13 Toolbar (android.support.v7.widget.Toolbar)12 ImageView (android.widget.ImageView)11 TabLayout (android.support.design.widget.TabLayout)10 ArrayList (java.util.ArrayList)9 RecyclerView (android.support.v7.widget.RecyclerView)8 FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)7 AppBarLayout (android.support.design.widget.AppBarLayout)6 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)6 MenuItem (android.view.MenuItem)5 ImageButton (android.widget.ImageButton)5 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)4 LargeTest (android.support.test.filters.LargeTest)4 MediumTest (android.support.test.filters.MediumTest)4