How can i set a tag for viewpager fragments?

前端 未结 3 1238
再見小時候
再見小時候 2020-12-31 01:41

I,m using slidingTabLayout with 4 tabs and a viewpager and 4 fragment class for every tab.

i need to reload one of my fragments (first tab) in my project when user

3条回答
  •  盖世英雄少女心
    2020-12-31 02:28

    Here is the method which is used by FragmentPagerAdapter to create the Fragment's tag name:

    private static String makeFragmentName(int viewId, long id) {
        return "android:switcher:" + viewId + ":" + id;
    }
    

    viewId is the id of the ViewPager.
    id is the position of the fragment inside the ViewPager.

    Example:

    String fragmentTag = makeFragmentName(myViewPager.getId(), 2);
    Fragment fragment = getSupportFragmentManager().findFragmentByTag(fragmentTag);
    

提交回复
热议问题