Skip to content

Instantly share code, notes, and snippets.

@hrules6872
Created February 23, 2016 16:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrules6872/24aed97f2e6b27f83e14 to your computer and use it in GitHub Desktop.
Save hrules6872/24aed97f2e6b27f83e14 to your computer and use it in GitHub Desktop.
UniversalFragmentPagerAdapter
public class UniversalFragmentPagerAdapter extends FragmentPagerAdapter {
private final String[] tabTitles;
private final Fragment[] tabFragments;
public UniversalFragmentPagerAdapter(@NonNull FragmentManager fm, String[] tabTitles,
@NonNull Fragment[] tabFragments) {
super(fm);
if (tabTitles != null && tabTitles.length != tabFragments.length) {
throw new IllegalArgumentException();
}
this.tabTitles = tabTitles;
this.tabFragments = tabFragments;
}
@Override public Fragment getItem(int position) {
return tabFragments[position];
}
@Override public int getCount() {
return tabFragments.length;
}
@Override public CharSequence getPageTitle(int position) {
return tabTitles != null ? tabTitles[position] : "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment