Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – The name ‘SuportMapFragment’ does not exist in the current context

Posted on November 14, 2022

Solution 1 :

As you are using the SupportMapFragment in a Fragment,you could call it like this:

SupportMapFragment mapFragment = Activity.SupportFragmentManager.FindFragmentById(Resource.Id.gmap).JavaCast<SupportMapFragment>();    
 if (mapFragment == null)
    {
     mapFragment = SupportMapFragment.NewInstance();
     mapFragment.GetMapAsync(this);
    }

refer the SupportMapFragment in your fragment xml:

<fragment xmlns_android="http://schemas.android.com/apk/res/android"
  xmlns_tools="http://schemas.android.com/tools"
  android_layout_width="match_parent"
  android_layout_height="match_parent"
  android_id="@+id/gmap"
  class="com.google.android.gms.maps.SupportMapFragment" />

update(like this,we could handle OnMapReady):

SupportMapFragment mapFragment = ChildFragmentManager.FindFragmentById(Resource.Id.gmap).JavaCast<SupportMapFragment>();    
mapFragment.GetMapAsync(this);

Problem :

I have implemented a map into my application though on a single view. After creating a few layouts I wanted to implement a bottom navigation view which meant I had to use fragments. I have already moved my activity’s code into my fragment named map_fragment, at first I wasn’t sure where to use FindFragmentById but according to findViewById in Fragment this should be used on the OnCreateView() lifecycle method.
My main problem now is capturing the map fragment, since I get the error The name ‘SuportMapFragment’ does not exist in the current context when using

    var mapFragment = (SupportMapFragment)SupportFragmentManager.FindFragmentById(Resource.Id.gmap);
        // Was able to use FragmentManager, but it returns null...
    // var mapFragment = (SupportMapFragment)FragmentManager.FindFragmentById(Resource.Id.gmap);
        mapFragment.GetMapAsync(this);

Here’s the full code

    public class map_fragment : Android.Support.V4.App.Fragment, IOnMapReadyCallback
    {
        public override void OnCreate(Bundle savedInstanceState)
            {
            base.OnCreate(savedInstanceState);
                // Create your fragment here       
        }
        public override void OnActivityCreated(Bundle savedInstanceState)
        {
            base.OnActivityCreated(savedInstanceState);
            // Capture the Map Fragment
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment
            base.OnCreateView(inflater, container, savedInstanceState);

            View view = inflater.Inflate(Resource.Layout.activity_main, container, false);
            var mapFragment = (SupportMapFragment)SupportFragmentManager.FindFragmentById(Resource.Id.gmap);
            //var mapFragment = (SupportMapFragment)FragmentManager.FindFragmentById(Resource.Id.gmap);
            mapFragment.GetMapAsync(this);

            return view;
        }
        public void OnMapReady(GoogleMap _map)
        {
            // Some other code here
        }
}

As requested this is my main_activity

   public class MainActivity : AppCompatActivity
    {
        BottomNavigationView bottomNavigation;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Initialize Xamarin Essentials for the Geolocation Service
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.main_frame);
            //var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            //if (toolbar != null)
            //{
            //    SetSupportActionBar(toolbar);
            //    SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            //    SupportActionBar.SetHomeButtonEnabled(false);
            //}

            bottomNavigation = FindViewById<BottomNavigationView>(Resource.Id.bottom_navigation);

            bottomNavigation.NavigationItemSelected += BottomNavigation_NavigationItemSelected;

            // Load the first fragment on creation
            LoadFragment(Resource.Id.profile_view);

        }

        private void BottomNavigation_NavigationItemSelected(object sender, BottomNavigationView.NavigationItemSelectedEventArgs e)
        {
            LoadFragment(e.Item.ItemId);
        }

        void LoadFragment(int id)
        {
            Android.Support.V4.App.Fragment fragment = null;
            switch (id)
            {
                case Resource.Id.profile_view:
                    fragment = profile_fragment.NewInstance();
                    break;
                case Resource.Id.map_view:
                    fragment = map_fragment.NewInstance();
                    break;
            }

            if (fragment == null)
                return;

            SupportFragmentManager.BeginTransaction()
                .Replace(Resource.Id.content_frame, fragment)
                .Commit();
        }

        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Android.Content.PM.Permission[] grantResults)
        {
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }

These are the tutorials I am using as a guide

  • https://devblogs.microsoft.com/xamarin/exploring-androids-bottom-navigation-view/
  • https://devblogs.microsoft.com/xamarin/exploring-androids-bottom-navigation-view/
READ  [ANSWERED] android - When i execute "setState" i get this error on emulator screen "Bad State: Stream has been already listened to."
Powered by Inline Related Posts

Comments

Comment posted by Saamer

Is there a difference between SupportMapFragment and SuportMapFragment that you are referring to? Could you also please share the layout file activity_main contents? What tutorial are you trying to follow?

Comment posted by Jeremy

The

Comment posted by Leo Zhu – MSFT

Did you refer to it in your layout ?

Comment posted by Jeremy

View view = inflater.Inflate(Resource.Layout.activity_main, container, false);

Comment posted by Leo Zhu – MSFT

you check the update above,add it in your activity_main.

Comment posted by Leo Zhu – MSFT

@Jeremy As if you want to handle

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress