-1

I'm trying to use support fragment manager in a fragment but it says SupportFragmentManager doesn't exist in the current context.

Here's my code

        private void Adapter_RateItemClick(object sender, DriversAdapterClickEventArgs e)
        {
                RatingFragment editAluminiFragment = new RatingFragment();
                var trans = SupportFragmentManager.BeginTransaction();
                editAluminiFragment.Show(trans, "Rate");
        }

I used

using FragmentManager = Android.Support.V4.App.FragmentManager; ? what should I do next

Gio Garcia
  • 77
  • 8
  • Most likely you will want to call into the activity and do the fragment transaction there. If you really want to do something inside the fragment, you should use the child fragment manager, see here: https://stackoverflow.com/questions/20676690/proper-use-of-sub-sub-fragments-with-childfragmentmanager – Daniel Nugent Mar 03 '20 at 00:22
  • Have a look at [this thread](https://stackoverflow.com/questions/29531643/how-to-get-access-to-getsupportfragmentmanager-or-supportfragmentmanager-in-frag) would help. – nevermore Mar 03 '20 at 05:25

1 Answers1

0

Firstly, there is documentation AndroidX Fragment class (it is similar for support v4, but you definitely should switch to AndroidX if you can). And as you can see there, there are two methods for working with fragments: getChildFragmentManager and getParentFragmentManager. I suppose you want to use child fragment manager to show some dialog, so in your case it will be

private void Adapter_RateItemClick(Object sender, DriversAdapterClickEventArgs e)
    {
            RatingFragment editAluminiFragment = new RatingFragment();
            editAluminiFragment.Show(getChildFragmentManager(), "Rate");
    }
Kiryl Tkach
  • 3,118
  • 5
  • 20
  • 36