Last active
April 12, 2016 11:33
-
-
Save hector6872/920cfb0f4de9c6e34cad to your computer and use it in GitHub Desktop.
UniversalFragmentStatePagerAdapter
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 UniversalFragmentStatePagerAdapter extends FragmentStatePagerAdapter { | |
private final String[] titles; | |
private final Fragment[] fragments; | |
public UniversalFragmentStatePagerAdapter(@NonNull FragmentManager fragmentManager, | |
String[] titles, @NonNull Fragment[] fragments) { | |
super(fragmentManager); | |
if (titles != null && titles.length != fragments.length) { | |
throw new IllegalArgumentException(); | |
} | |
this.titles = titles; | |
this.fragments = fragments; | |
} | |
@Override public Fragment getItem(int position) { | |
return fragments[position]; | |
} | |
@Override public int getCount() { | |
return fragments.length; | |
} | |
@Override public CharSequence getPageTitle(int position) { | |
return titles != null ? titles[position] : ""; | |
} | |
@Override public Object instantiateItem(ViewGroup container, int position) { | |
return super.instantiateItem(container, position); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment