I have a FragmentActivity
with the following xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
and the view pager class is as follows:
public class MyPagerAdapter extends FragmentStatePagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int i) {
switch (i) {
case 0:
// profile fragment activity
Fragment f = new ProfileFragment();
return new ProfileFragment();
case 1:
// radar fragment activity
return new RadarFragment();
case 2:
// matches fragment activity
return new MatchesFragment();
}
return null;
}
@Override
public int getCount() {
return 3;
}
}
I also have a BroadcastReceiver
class that has an instance variable of my custom FragmentActivity
. Through this instance variable I would like to obtain any of the fragments above. I understand there are FragmentManager.findFragmentById()
and findFragmentByTag()
methods but I cant seem to find a way of using that in this case.