Search in sources :

Example 1 with FragmentPagerAdapter

use of android.support.v13.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.v13.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 3 with FragmentPagerAdapter

use of android.support.v13.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 4 with FragmentPagerAdapter

use of android.support.v13.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)

Example 5 with FragmentPagerAdapter

use of android.support.v13.app.FragmentPagerAdapter in project leo-app by LCA311.

the class WrapperQRActivity method onCreate.

/*    private ZXingScannerView scV;
    public static Button scan;
    private final int MY_PERMISSIONS_REQUEST_USE_CAMERA = 0;
    private boolean runningScan; */
@Override
protected void onCreate(Bundle savedInstanceState) {
    /*   super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wrapper_qr); */
    //---- START TOOLBAR ---- //
    Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar);
    //        runningScan = false;
    setSupportActionBar(myToolbar);
    //If it's stupid, but it works it's not stupid
    getSupportActionBar().setTitle(Html.fromHtml("<font color=\"#ffffff\">" + getString(R.string.toolbar_title) + "</font>"));
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    //---- ENDE TOOLBAR ---- //
    //---- START TABS ---- //
    mViewPager = (ViewPager) findViewById(R.id.pager);
    FragmentPagerAdapter adapt = new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            if (position == 0)
                //QRActivity ist ein Fragment trotz des Namens
                return new QRActivity();
            else
                //ScanActivity ist ein Fragment trotz des Namens
                return new ScanActivity();
        }

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

        @Override
        public CharSequence getPageTitle(int position) {
            if (position == 0)
                return getString(R.string.toolbar_qr);
            else
                return getString(R.string.toolbar_scan);
        }
    };
    mViewPager.setAdapter(adapt);
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tablayout);
    tabLayout.setupWithViewPager(mViewPager);
//---- ENDE TABS ---- //
/*        sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
        sqlh = new SQLiteHandler(getApplicationContext());

        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                scan.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        scan();
                    }
                });
            }
        }, 100); */
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) TabLayout(android.support.design.widget.TabLayout) Toolbar(android.support.v7.widget.Toolbar)

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