当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Fragments inside a ViewPager - how to get a list of all child fragments

问题描述:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: