Search in sources :

Example 1 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project BoomMenu by Nightonke.

the class FragmentActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragment);
    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    assert viewPager != null;
    viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            return new BMBFragment().position(position);
        }

        @Override
        public int getCount() {
            return 50;
        }
    });
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) ViewPager(android.support.v4.view.ViewPager) Fragment(android.support.v4.app.Fragment)

Example 2 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project LuaViewSDK by alibaba.

the class FixedFragmentStatePagerAdapter method instantiateItem.

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final Object fragment = super.instantiateItem(container, position);
    try {
        final Field saveFragmentStateField = Fragment.class.getDeclaredField("mSavedFragmentState");
        saveFragmentStateField.setAccessible(true);
        final Bundle savedFragmentState = (Bundle) saveFragmentStateField.get(fragment);
        if (savedFragmentState != null) {
            savedFragmentState.setClassLoader(Fragment.class.getClassLoader());
        }
    } catch (Exception e) {
        Log.w("FragmentPagerAdapter", "Could not get mSavedFragmentState field: " + e);
    }
    return fragment;
}
Also used : Field(java.lang.reflect.Field) Bundle(android.os.Bundle) Fragment(android.support.v4.app.Fragment)

Example 3 with FragmentPagerAdapter

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

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("标题");
    setSupportActionBar(toolbar);
    mTabLayout = (TabLayout) findViewById(R.id.id_tablayout);
    mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
    mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

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

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

        @Override
        public CharSequence getPageTitle(int position) {
            return "Page " + position;
        }
    });
    mTabLayout.setupWithViewPager(mViewPager);
}
Also used : SimpleFragment(com.zhy.autolayout.test.widgets.fragments.SimpleFragment) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) Fragment(android.support.v4.app.Fragment) SimpleFragment(com.zhy.autolayout.test.widgets.fragments.SimpleFragment) Toolbar(android.support.v7.widget.Toolbar)

Example 4 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project StatusBarUtil by laobie.

the class UseInFragmentActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_use_in_fragment);
    mVpHome = (ViewPager) findViewById(R.id.vp_home);
    mBottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
    mBottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.ic_favorite, "One")).addItem(new BottomNavigationItem(R.drawable.ic_gavel, "Two")).addItem(new BottomNavigationItem(R.drawable.ic_grade, "Three")).addItem(new BottomNavigationItem(R.drawable.ic_group_work, "Four")).initialise();
    mBottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {

        @Override
        public void onTabSelected(int position) {
            mVpHome.setCurrentItem(position);
        }

        @Override
        public void onTabUnselected(int position) {
        }

        @Override
        public void onTabReselected(int position) {
        }
    });
    mFragmentList.add(new ImageFragment());
    mFragmentList.add(new SimpleFragment());
    mFragmentList.add(new SimpleFragment());
    mFragmentList.add(new SimpleFragment());
    mVpHome.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

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

        @Override
        public void onPageSelected(int position) {
            mBottomNavigationBar.selectTab(position);
            switch(position) {
                case 0:
                    break;
                default:
                    Random random = new Random();
                    int color = 0xff000000 | random.nextInt(0xffffff);
                    if (mFragmentList.get(position) instanceof SimpleFragment) {
                        ((SimpleFragment) mFragmentList.get(position)).setTvTitleBackgroundColor(color);
                    }
                    break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    mVpHome.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }
    });
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) ViewPager(android.support.v4.view.ViewPager) Fragment(android.support.v4.app.Fragment) BottomNavigationBar(com.ashokvarma.bottomnavigation.BottomNavigationBar) Random(java.util.Random) BottomNavigationItem(com.ashokvarma.bottomnavigation.BottomNavigationItem)

Example 5 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project quickstart-android by firebase.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Create the adapter that will return a fragment for each section
    mPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

        private final Fragment[] mFragments = new Fragment[] { new RecentPostsFragment(), new MyPostsFragment(), new MyTopPostsFragment() };

        private final String[] mFragmentNames = new String[] { getString(R.string.heading_recent), getString(R.string.heading_my_posts), getString(R.string.heading_my_top_posts) };

        @Override
        public Fragment getItem(int position) {
            return mFragments[position];
        }

        @Override
        public int getCount() {
            return mFragments.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentNames[position];
        }
    };
    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mPagerAdapter);
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    // Button launches NewPostActivity
    findViewById(R.id.fab_new_post).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, NewPostActivity.class));
        }
    });
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) Intent(android.content.Intent) RecentPostsFragment(com.google.firebase.quickstart.database.fragment.RecentPostsFragment) Fragment(android.support.v4.app.Fragment) MyPostsFragment(com.google.firebase.quickstart.database.fragment.MyPostsFragment) MyTopPostsFragment(com.google.firebase.quickstart.database.fragment.MyTopPostsFragment) View(android.view.View) MyTopPostsFragment(com.google.firebase.quickstart.database.fragment.MyTopPostsFragment) RecentPostsFragment(com.google.firebase.quickstart.database.fragment.RecentPostsFragment) TabLayout(android.support.design.widget.TabLayout) MyPostsFragment(com.google.firebase.quickstart.database.fragment.MyPostsFragment)

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