Search in sources :

Example 11 with FragmentPagerAdapter

use of android.support.v13.app.FragmentPagerAdapter in project BGARefreshLayout-Android by bingoogolapple.

the class BGAStickyNavLayout method regetNestedContentView.

/**
     * 重新获取嵌套的内容视图
     */
private void regetNestedContentView() {
    int currentItem = mDirectViewPager.getCurrentItem();
    PagerAdapter adapter = mDirectViewPager.getAdapter();
    if (adapter instanceof FragmentPagerAdapter || adapter instanceof FragmentStatePagerAdapter) {
        Fragment item = (Fragment) adapter.instantiateItem(mDirectViewPager, currentItem);
        mNestedContentView = item.getView();
        // 清空之前的
        mNestedNormalView = null;
        mNestedAbsListView = null;
        mNestedRecyclerView = null;
        mNestedScrollView = null;
        mNestedWebView = null;
        if (mNestedContentView instanceof AbsListView) {
            mNestedAbsListView = (AbsListView) mNestedContentView;
            mNestedAbsListView.setOnScrollListener(mLvOnScrollListener);
            if (!isHeaderViewCompleteInvisible()) {
                mNestedAbsListView.setSelection(0);
            }
        } else if (mNestedContentView instanceof RecyclerView) {
            mNestedRecyclerView = (RecyclerView) mNestedContentView;
            mNestedRecyclerView.removeOnScrollListener(mRvOnScrollListener);
            mNestedRecyclerView.addOnScrollListener(mRvOnScrollListener);
            if (!isHeaderViewCompleteInvisible()) {
                mNestedRecyclerView.scrollToPosition(0);
            }
        } else if (mNestedContentView instanceof ScrollView) {
            mNestedScrollView = (ScrollView) mNestedContentView;
            if (!isHeaderViewCompleteInvisible()) {
                mNestedScrollView.scrollTo(mNestedScrollView.getScrollX(), 0);
            }
        } else if (mNestedContentView instanceof WebView) {
            mNestedWebView = (WebView) mNestedContentView;
            if (!isHeaderViewCompleteInvisible()) {
                mNestedWebView.scrollTo(mNestedWebView.getScrollX(), 0);
            }
        } else {
            mNestedNormalView = mNestedContentView;
        }
    } else {
        throw new IllegalStateException(BGAStickyNavLayout.class.getSimpleName() + "的第三个子控件为ViewPager时,其adapter必须是FragmentPagerAdapter或者FragmentStatePagerAdapter");
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) ScrollView(android.widget.ScrollView) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) WebView(android.webkit.WebView) Fragment(android.support.v4.app.Fragment) PagerAdapter(android.support.v4.view.PagerAdapter) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter)

Example 12 with FragmentPagerAdapter

use of android.support.v13.app.FragmentPagerAdapter in project AndroidDevMetrics by frogermcs.

the class MetricsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.adm_activity_metrics);
    btnActivities = (Button) findViewById(R.id.btnActivities);
    btnDagger2 = (Button) findViewById(R.id.btnDagger2);
    vpMetrics = (ViewPager) findViewById(R.id.vpMetrics);
    activitiesMetricsFragment = new ActivitiesMetricsFragment();
    dagger2MetricsFragment = new Dagger2MetricsFragment();
    FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                return activitiesMetricsFragment;
            } else if (position == 1) {
                return dagger2MetricsFragment;
            }
            return null;
        }

        @Override
        public int getCount() {
            return 2;
        }
    };
    vpMetrics.setAdapter(fragmentPagerAdapter);
    vpMetrics.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            if (position == 0) {
                activitiesPageSelected();
            } else if (position == 1) {
                daggerPageSelected();
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    btnActivities.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            vpMetrics.setCurrentItem(0);
        }
    });
    btnDagger2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            vpMetrics.setCurrentItem(1);
        }
    });
    activitiesPageSelected();
}
Also used : Dagger2MetricsFragment(com.frogermcs.androiddevmetrics.internal.ui.fragment.Dagger2MetricsFragment) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) ActivitiesMetricsFragment(com.frogermcs.androiddevmetrics.internal.ui.fragment.ActivitiesMetricsFragment) ViewPager(android.support.v4.view.ViewPager) View(android.view.View)

Example 13 with FragmentPagerAdapter

use of android.support.v13.app.FragmentPagerAdapter in project AndroidAutoLayout by hongyangAndroid.

the class CategoryActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_category);
    mTabLayout = (TabLayout) findViewById(R.id.id_tablayout);
    mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
    mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int i) {
            return new SimpleFragment();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTabTitles[position];
        }

        @Override
        public int getCount() {
            return mTabTitles.length;
        }
    });
    mTabLayout.setupWithViewPager(mViewPager);
}
Also used : SimpleFragment(com.zhy.sample.fragment.SimpleFragment) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) Fragment(android.support.v4.app.Fragment) SimpleFragment(com.zhy.sample.fragment.SimpleFragment)

Example 14 with FragmentPagerAdapter

use of android.support.v13.app.FragmentPagerAdapter in project FlowLayout by hongyangAndroid.

the class CategoryActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_category);
    mTabLayout = (TabLayout) findViewById(R.id.id_tablayout);
    mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
    mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int i) {
            switch(i) {
                case 0:
                    return new SimpleFragment();
                case 1:
                    return new LimitSelectedFragment();
                case 2:
                    return new EventTestFragment();
                case 3:
                    return new ScrollViewTestFragment();
                case 4:
                    return new SingleChooseFragment();
                case 5:
                    return new GravityFragment();
                case 6:
                    return new ListViewTestFragment();
                default:
                    return new EventTestFragment();
            }
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTabTitles[position];
        }

        @Override
        public int getCount() {
            return mTabTitles.length;
        }
    });
    mTabLayout.setupWithViewPager(mViewPager);
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) Fragment(android.support.v4.app.Fragment)

Example 15 with FragmentPagerAdapter

use of android.support.v13.app.FragmentPagerAdapter in project Android-Boilerplate by hitherejoe.

the class DetailActivity method setupViewPager.

private void setupViewPager() {
    mBeaconDetailViewPager.setOffscreenPageLimit(2);
    mBeaconDetailViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

        String[] titles = getResources().getStringArray(R.array.detail_fragment_titles);

        @Override
        public Fragment getItem(int position) {
            switch(position) {
                case 0:
                    return DetailFragment.newInstance((ArrayList<String>) mCharacter.films);
                case 1:
                    return DetailFragment.newInstance((ArrayList<String>) mCharacter.vehicles);
                case 2:
                    return DetailFragment.newInstance((ArrayList<String>) mCharacter.species);
                case 3:
                    return DetailFragment.newInstance((ArrayList<String>) mCharacter.starships);
                default:
                    return DetailFragment.newInstance(new ArrayList<String>());
            }
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }

        @Override
        public int getCount() {
            return titles.length;
        }
    });
    mTabLayout.setupWithViewPager(mBeaconDetailViewPager);
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) ArrayList(java.util.ArrayList) DetailFragment(com.hitherejoe.androidboilerplate.ui.fragment.DetailFragment) Fragment(android.support.v4.app.Fragment)

Aggregations

FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)29 Fragment (android.support.v4.app.Fragment)20 ViewPager (android.support.v4.view.ViewPager)8 View (android.view.View)5 Intent (android.content.Intent)3 TabLayout (android.support.design.widget.TabLayout)3 TabPageIndicator (com.viewpagerindicator.TabPageIndicator)3 Toolbar (android.support.v7.widget.Toolbar)2 TextView (android.widget.TextView)2 PageIndicator (com.viewpagerindicator.PageIndicator)2 SuppressLint (android.annotation.SuppressLint)1 Fragment (android.app.Fragment)1 FragmentPagerAdapter (android.support.v13.app.FragmentPagerAdapter)1 FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 ListFragment (android.support.v4.app.ListFragment)1 PagerAdapter (android.support.v4.view.PagerAdapter)1 OnPageChangeListener (android.support.v4.view.ViewPager.OnPageChangeListener)1 RecyclerView (android.support.v7.widget.RecyclerView)1 DisplayMetrics (android.util.DisplayMetrics)1