Created
February 23, 2016 16:11
-
-
Save hector6872/24aed97f2e6b27f83e14 to your computer and use it in GitHub Desktop.
UniversalFragmentPagerAdapter
This file contains hidden or 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 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