Android FragmentStatePagerAdapter

后端 未结 5 1332
太阳男子
太阳男子 2021-02-01 18:02

I\'m working with a FragmentStatePagerAdapter using this example.

The MyAdapter class is implemented as follows:

public static class MyAdapter extends Fr         


        
5条回答
  •  温柔的废话
    2021-02-01 18:21

    Do not need modify the FragmentPagerAdapter, because fragments are cached by the FragmentManager. So you must need find inside it. Use this function to find the fragment by pager adapter position.

    public Fragment findFragmentByPosition(int position) {
        FragmentPagerAdapter fragmentPagerAdapter = getFragmentPagerAdapter();
        return getSupportFragmentManager().findFragmentByTag(
                "android:switcher:" + getViewPager().getId() + ":"
                        + fragmentPagerAdapter.getItemId(position));
    }
    

    Sample code for v4 support api.

提交回复
热议问题