Created
November 27, 2015 09:59
-
-
Save devflow/6d0ae410e8decfd8f488 to your computer and use it in GitHub Desktop.
IndexedFragmentPagerAdapter.java
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 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