Created
March 25, 2018 14:20
-
-
Save ameliacv/6ebf1b60323222a07de77e908ee3d4fb 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 SectionsPagerAdapter extends FragmentPagerAdapter { | |
private final List<Fragment> mFragmentList = new ArrayList<>(); | |
private final List<String> mFragmentTitleList = new ArrayList<>(); | |
public SectionsPagerAdapter(FragmentManager manager) { | |
super(manager); | |
} | |
@Override | |
public Fragment getItem(int position) { | |
return mFragmentList.get(position); | |
} | |
@Override | |
public int getCount() { | |
return mFragmentList.size(); | |
} | |
public void addFragment(Fragment fragment, String title, int position) { | |
mFragmentList.add(position, fragment); | |
mFragmentTitleList.add(position, title); | |
} | |
public void removeFragment(Fragment fragment, int position) { | |
mFragmentList.remove(position); | |
mFragmentTitleList.remove(position); | |
} | |
@Override | |
public CharSequence getPageTitle(int position) { | |
return mFragmentTitleList.get(position); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment