Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know Fragment id for the fragment(s) provided by the tabbed activity template

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.

like image 802
Diptangsu Goswami Avatar asked Nov 08 '22 08:11

Diptangsu Goswami


1 Answers

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;
}
like image 82
Aman Jain Avatar answered Nov 27 '22 00:11

Aman Jain