Search in sources :

Example 21 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project RxJavaSamples by rengwuxian.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    setSupportActionBar(toolBar);
    viewPager.setAdapter(new FragmentPagerAdapter(getFragmentManager()) {

        @Override
        public int getCount() {
            return 6;
        }

        @Override
        public Fragment getItem(int position) {
            switch(position) {
                case 0:
                    return new ElementaryFragment();
                case 1:
                    return new MapFragment();
                case 2:
                    return new ZipFragment();
                case 3:
                    return new TokenFragment();
                case 4:
                    return new TokenAdvancedFragment();
                case 5:
                    return new CacheFragment();
                default:
                    return new ElementaryFragment();
            }
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch(position) {
                case 0:
                    return getString(R.string.title_elementary);
                case 1:
                    return getString(R.string.title_map);
                case 2:
                    return getString(R.string.title_zip);
                case 3:
                    return getString(R.string.title_token);
                case 4:
                    return getString(R.string.title_token_advanced);
                case 5:
                    return getString(R.string.title_cache);
                default:
                    return getString(R.string.title_elementary);
            }
        }
    });
    tabLayout.setupWithViewPager(viewPager);
}
Also used : TokenFragment(com.rengwuxian.rxjavasamples.module.token_4.TokenFragment) ZipFragment(com.rengwuxian.rxjavasamples.module.zip_3.ZipFragment) FragmentPagerAdapter(android.support.v13.app.FragmentPagerAdapter) MapFragment(com.rengwuxian.rxjavasamples.module.map_2.MapFragment) CacheFragment(com.rengwuxian.rxjavasamples.module.cache_6.CacheFragment) Fragment(android.app.Fragment) TokenFragment(com.rengwuxian.rxjavasamples.module.token_4.TokenFragment) ZipFragment(com.rengwuxian.rxjavasamples.module.zip_3.ZipFragment) CacheFragment(com.rengwuxian.rxjavasamples.module.cache_6.CacheFragment) MapFragment(com.rengwuxian.rxjavasamples.module.map_2.MapFragment) ElementaryFragment(com.rengwuxian.rxjavasamples.module.elementary_1.ElementaryFragment) TokenAdvancedFragment(com.rengwuxian.rxjavasamples.module.token_advanced_5.TokenAdvancedFragment) TokenAdvancedFragment(com.rengwuxian.rxjavasamples.module.token_advanced_5.TokenAdvancedFragment) ElementaryFragment(com.rengwuxian.rxjavasamples.module.elementary_1.ElementaryFragment)

Example 22 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project Fragmentation by YoKeyword.

the class FragmentationDelegate method findStackFragment.

/**
     * find Fragment from FragmentStack
     */
@SuppressWarnings("unchecked")
<T extends SupportFragment> T findStackFragment(Class<T> fragmentClass, String toFragmentTag, FragmentManager fragmentManager) {
    fragmentManager = checkFragmentManager(fragmentManager, null);
    if (fragmentManager == null)
        return null;
    Fragment fragment = null;
    if (toFragmentTag == null) {
        // 如果是 查找Fragment时,则有可能是在FragmentPagerAdapter/FragmentStatePagerAdapter中,这种情况下,
        // 它们的Tag是以android:switcher开头,所以这里我们使用下面的方式
        List<Fragment> fragmentList = fragmentManager.getFragments();
        if (fragmentList == null)
            return null;
        int sizeChildFrgList = fragmentList.size();
        for (int i = sizeChildFrgList - 1; i >= 0; i--) {
            Fragment brotherFragment = fragmentList.get(i);
            if (brotherFragment instanceof SupportFragment && brotherFragment.getClass().getName().equals(fragmentClass.getName())) {
                fragment = brotherFragment;
                break;
            }
        }
    } else {
        fragment = fragmentManager.findFragmentByTag(toFragmentTag);
    }
    if (fragment == null) {
        return null;
    }
    return (T) fragment;
}
Also used : Fragment(android.support.v4.app.Fragment)

Example 23 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project ViewPagerIndicator by JakeWharton.

the class SampleTabsStyled method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_tabs);
    FragmentPagerAdapter adapter = new GoogleMusicAdapter(getSupportFragmentManager());
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(adapter);
    TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
    indicator.setViewPager(pager);
}
Also used : TabPageIndicator(com.viewpagerindicator.TabPageIndicator) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) ViewPager(android.support.v4.view.ViewPager)

Example 24 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project ViewPagerIndicator by JakeWharton.

the class SampleTabsWithIcons method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_tabs);
    FragmentPagerAdapter adapter = new GoogleMusicAdapter(getSupportFragmentManager());
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(adapter);
    TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
    indicator.setViewPager(pager);
}
Also used : TabPageIndicator(com.viewpagerindicator.TabPageIndicator) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) ViewPager(android.support.v4.view.ViewPager)

Example 25 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project ABPlayer by winkstu.

the class DonghuaActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    // 无标题
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.donghua_tab);
    backButton = findViewById(R.id.logobutton);
    titleText = (TextView) findViewById(R.id.textViewTitle);
    FragmentPagerAdapter adapter = null;
    mAreaType = getIntent().getIntExtra("AreaType", 1);
    Log.d("QAQ", "----->" + mAreaType + titleText.getText());
    switch(mAreaType) {
        case 1:
            titleText.setText("番剧");
            adapter = new BankumiTabAdapter(getSupportFragmentManager());
            break;
        case 2:
            titleText.setText("动画");
            adapter = new DonghuaTabAdapter(getSupportFragmentManager());
            break;
        case 3:
            titleText.setText("音乐");
            adapter = new MusicTabAdapter(getSupportFragmentManager());
            break;
        case 4:
            titleText.setText("游戏");
            adapter = new YouxiTabAdapter(getSupportFragmentManager());
            break;
        case 5:
            titleText.setText("科学·技术");
            adapter = new KejiTabAdapter(getSupportFragmentManager());
            break;
        case 6:
            titleText.setText("娱乐");
            adapter = new YuleTabAdapter(getSupportFragmentManager());
            break;
        case 7:
            titleText.setText("电影");
            adapter = new DianyingTabAdapter(getSupportFragmentManager());
            break;
        case 8:
            titleText.setText("排行榜");
            adapter = new RankAdapter(getSupportFragmentManager());
            break;
        default:
            titleText.setText("电影");
            adapter = new DianyingTabAdapter(getSupportFragmentManager());
            break;
    }
    // 视图切换器
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setOffscreenPageLimit(1);
    pager.setAdapter(adapter);
    // 页面指示器
    PageIndicator indicator = (PageIndicator) findViewById(R.id.indicator);
    indicator.setViewPager(pager);
    backButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            finish();
        }
    });
}
Also used : PageIndicator(com.viewpagerindicator.PageIndicator) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) YuleTabAdapter(com.vanco.abplayer.adapter.YuleTabAdapter) YouxiTabAdapter(com.vanco.abplayer.adapter.YouxiTabAdapter) ViewPager(android.support.v4.view.ViewPager) View(android.view.View) TextView(android.widget.TextView) BankumiTabAdapter(com.vanco.abplayer.adapter.BankumiTabAdapter) KejiTabAdapter(com.vanco.abplayer.adapter.KejiTabAdapter) DianyingTabAdapter(com.vanco.abplayer.adapter.DianyingTabAdapter) OnClickListener(android.view.View.OnClickListener) MusicTabAdapter(com.vanco.abplayer.adapter.MusicTabAdapter) RankAdapter(com.vanco.abplayer.adapter.RankAdapter) DonghuaTabAdapter(com.vanco.abplayer.adapter.DonghuaTabAdapter)

Aggregations

FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)29 Fragment (android.support.v4.app.Fragment)23 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 FragmentTransaction (android.support.v4.app.FragmentTransaction)2 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 Bundle (android.os.Bundle)1 FragmentPagerAdapter (android.support.v13.app.FragmentPagerAdapter)1 FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)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