Back to project page Android-Navigation-Drawer-with-Tabs.
The source code is released under:
Apache License
If you think the Android project Android-Navigation-Drawer-with-Tabs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.navigationdrawertest; /*w w w . j a v a 2 s . com*/ import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class FragmentMain extends Fragment { private ViewPager viewPager; @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); } public FragmentMain() { // Required empty public constructor } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); viewPager = (ViewPager) getView().findViewById(R.id.pager); viewPager.setAdapter(new MyAdapter(getFragmentManager())); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_main, container, false); } } class MyAdapter extends FragmentStatePagerAdapter { public MyAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int arg0) { Fragment fragment = null; if (arg0 == 0) { fragment = new Home1(); } if (arg0 == 1) { fragment = new Home2(); } if (arg0 == 2) { fragment = new Home3(); } if (arg0 == 3) { fragment = new Home4(); } return fragment; } @Override public int getCount() { return 4; } @Override public CharSequence getPageTitle(int position) { if (position == 0) { return "Home Tab 1"; } if (position == 1) { return "Home Tab 2"; } if (position == 2) { return "Home Tab 3"; } if (position == 3) { return "Home Tab 4"; } return null; } }