Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
IndexedFragmentPagerAdapter.java
public class IndexedFragmentPagerAdapter extends FragmentPagerAdapter {
public SparseArray<Fragment> fragments = new SparseArray<>();
public IndexedFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return null;
}
@Override
public int getCount() {
return 0;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Fragment fragment = (Fragment) super.instantiateItem(container, position);
fragments.put(position, fragment);
return fragment;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
fragments.remove(position);
super.destroyItem(container, position, object);
}
public Fragment getRegisteredFragment(int position) {
return fragments.get(position);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment