Skip to content

Instantly share code, notes, and snippets.

@ameliacv
Created March 25, 2018 14:20
Show Gist options
  • Save ameliacv/6ebf1b60323222a07de77e908ee3d4fb to your computer and use it in GitHub Desktop.
Save ameliacv/6ebf1b60323222a07de77e908ee3d4fb to your computer and use it in GitHub Desktop.
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