Referencing the SupportFragmentManager in a fragment
From a Fragment you can get the fragment Manager with getFragmentManager()
or getChildFragmentManager()
if you have nested fragments, But you still need your Activity to extend FragmentActivity, you can have the viewpager within it. Or you can have something like this:
so you can later replace the MainFragment with some other Fragment.
user3548779
Updated on June 05, 2022Comments
-
user3548779 almost 2 years
I am coding a Google Maps application in Xamarin and have successfully extended the class to use
Android.Support.V4.App.FragmentActivity
.I am now wanting to change the
Android.Support.V4.App.FragmentActivity
to be aAndroid.Support.V4.App.Fragment
so that I can have aViewPager
that has a Google Map fragment.As I have now changed the class to extend from
Android.Support.V4.App.Fragment
, I cannot reference theSupportFragmentManager
.Here is my code:
private void InitMapFragment() { _mapFragment = SupportFragmentManager.FindFragmentByTag("map") as SupportMapFragment; if (_mapFragment == null) { GoogleMapOptions mapOptions = new GoogleMapOptions() .InvokeMapType(GoogleMap.MapTypeNormal) .InvokeZoomControlsEnabled(true) .InvokeCompassEnabled(true); FragmentTransaction fragTx = SupportFragmentManager.BeginTransaction(); _mapFragment = SupportMapFragment.NewInstance(mapOptions); fragTx.Add(Resource.Id.map, _mapFragment, "map"); fragTx.Commit(); } }
How do I reference the
SupportFragmentManager
in aAndroid.Support.V4.App.Fragment
?Thanks in advance
-
user3548779 almost 10 yearsHow do I call the SupportFragmentManager, not the FragmentManager?
-
ILovemyPoncho almost 10 yearsfrom a Fragment you can all getActivity().getSupportFragmentManager()