How can I get a list of all child fragments that I have set up using a v4 viewpager with a FragmentPagerAdapter
The viewpager exists on the main activity
How can I get a list of all child fragments that I have set up using a v4 viewpager with a FragmentPagerAdapter
The viewpager exists on the main activity
You can use the getCount()
and getItem(int)
methods to iterate through all the fragments in your FragmentPagerAdapter
. For example:
List<Fragment> allFragments = new LinkedList<Fragment>();
for (int i = 0; i < adapter.getCount(); i++) {
Fragment f = adapter.getItem(i);
allFragments.add(f);
}
See the PagerAdapter and FragmentPagerAdapter classes for an explanation of how these methods work.