问题
I have used the tabbed activity template provided by android studio but i can't happen to find the id 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 fragments. But I can't figure out how to set the id for the different fragments either from .xml or in .java and without the id I can't perform inter fragment communication.
回答1:
Now for retrieving a fragment
Fragment f = getSupportFragmentManager().findFragmentByTag(getFragmentTag(mViewPager.getId(), mViewPager.getCurrentItem()));
public static String getFragmentTag(int viewId, long id) {
return "android:switcher:" + viewId + ":" + id;
}
来源:https://stackoverflow.com/questions/39555081/how-to-know-fragment-id-for-the-fragments-provided-by-the-tabbed-activity-temp