How to find out the fragment identifier for the fragment (s) provided by the tab activity template

I used the tab activity template provided by Android studio, but I can not find the identifier for the different fragments used. the template had only one .xml and .java for all three fragments. I made a few changes and made three separate .xml and .java for the three snippets. But I can’t understand how to set the identifier for different fragments from either .xml or .java, and without id I can’t exchange fragments between fragments.

+4
source share
1 answer

Now to extract the fragment

Fragment f = getSupportFragmentManager().findFragmentByTag(getFragmentTag(mViewPager.getId(), mViewPager.getCurrentItem()));


public static String getFragmentTag(int viewId, long id) {
    return "android:switcher:" + viewId + ":" + id;
}
0
source

Source: https://habr.com/ru/post/1654958/


All Articles