2

The following line does not compile:

var mapFragment = FragmentManager.FindFragmentById<MapFragment>(Resource.Id.map);

Error CS0120 An object reference is required for the non-static field, method, or property 'FragmentManager.FindFragmentById(int)'

My axml is the following:

  <fragment xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/map"
            android:layout_width="200dp"
            android:layout_height="200dp"
            class="com.google.android.gms.maps.MapFragment" />

I am referencing the following documentation:

Any suggestions?

Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118

2 Answers2

2

As per your targeted doc suggest i found this one.

_myMapFragment = MapFragment.NewInstance();
 FragmentTransaction tx = FragmentManager.BeginTransaction();
 tx.Add(Resource.Id.map, _myMapFragment);
 tx.Commit();
 GoogleMap map = myMapFragment.Map;
 if (map != null) {
 // The GoogleMap object is ready to go.
 }
pRaNaY
  • 24,642
  • 24
  • 96
  • 146
  • I get a compile error: FragmentTransaction tx = FragmentManager.BeginTransaction(); "An object reference is required for the non-static field" – Scott Nimrod Oct 18 '15 at 13:41
1

FragmentManager is a getter property off Activity class, if your code is not executing within the context (method) of an Activity, it needs to go off a context object.

Leo Nix
  • 2,085
  • 2
  • 24
  • 37