Skip to content

Instantly share code, notes, and snippets.

@devflow
Created November 27, 2015 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devflow/6d0ae410e8decfd8f488 to your computer and use it in GitHub Desktop.
Save devflow/6d0ae410e8decfd8f488 to your computer and use it in GitHub Desktop.
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