Created
March 9, 2017 13:53
-
-
Save maydin/026038253bb414640421939ada17781e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ViewPagerFragment extends Fragment { | |
public static final String PAGE_TITLE = "Tab1"; | |
ViewPager viewPager; | |
ViewPagerAdapter viewPagerAdapter; | |
public ViewPagerFragment() { | |
// Required empty public constructor | |
} | |
/** | |
* Use this factory method to create a new instance of | |
* this fragment | |
* @return A new instance of fragment ViewPagerFragment. | |
*/ | |
public static ViewPagerFragment newInstance() { | |
ViewPagerFragment fragment = new ViewPagerFragment(); | |
return fragment; | |
} | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
// Inflate the layout for this fragment | |
View view = inflater.inflate(R.layout.fragment_view_pager, container, false); | |
viewPager = (ViewPager) view.findViewById(R.id.viewpager); | |
viewPagerAdapter = new ViewPagerAdapter(getChildFragmentManager()); | |
viewPager.setAdapter(viewPagerAdapter); | |
return view; | |
} | |
public static class ViewPagerAdapter extends FragmentStatePagerAdapter { | |
private static final int NUM_ITEMS = 2; | |
public ViewPagerAdapter(FragmentManager fm) { | |
super(fm); | |
} | |
@Override | |
public int getCount() { | |
return NUM_ITEMS; | |
} | |
@Override | |
public Fragment getItem(int position) { | |
if(position == 0){ | |
return InnerViewPager.newInstance(); | |
} | |
else { | |
return Fragment2.newInstance(); | |
} | |
} | |
@Override | |
public CharSequence getPageTitle(int position) { | |
if(position == 0){ | |
return ViewPagerFragment.PAGE_TITLE; | |
} | |
else { | |
return Fragment2.PAGE_TITLE; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment