Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Cannot convert type 'Android.Support.V4.App.Fragment' to 'Android.Gms.Maps.MapFragment'

$
0
0

I am using Xamarin and am recoding a Google Maps application to use Android.Support.V4.App.Fragments with a View Pager.

Here is my code:

    private void InitMapFragment()
    {
        _mapFragment = FragmentManager.FindFragmentByTag("map") as MapFragment;
        if (_mapFragment == null)
        {
            GoogleMapOptions mapOptions = new GoogleMapOptions()
                .InvokeMapType(GoogleMap.MapTypeNormal)
                .InvokeZoomControlsEnabled(true)
                .InvokeCompassEnabled(true);

            FragmentTransaction fragTx = FragmentManager.BeginTransaction();
            _mapFragment = MapFragment.NewInstance(mapOptions);
            fragTx.Add(Resource.Id.mapWithOverlay, _mapFragment, "map");
            fragTx.Commit();
        }
    }

Because I am now extending the Activity to use Android.Support.V4.App.Fragment, I am getting the following errors when compiling:

Error CS0039: Cannot convert type 'Android.Support.V4.App.Fragment' to 'Android.Gms.Maps.MapFragment' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion (CS0039)

At the line:

_mapFragment = FragmentManager.FindFragmentByTag("map") as MapFragment

As well as:

Error CS0029: Cannot implicitly convert type 'Android.Support.V4.App.FragmentTransaction' to 'Android.App.FragmentTransaction' (CS0029)

At the line:

FragmentTransaction fragTx = FragmentManager.BeginTransaction()

Can I have some help to get this code working?

Thanks in advance


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>