I have a class which is derived from Android.App.DialogFragment
, now I need to show this dialog fragment. I am trying to show this dialog fragment from a class which is derived from Android.Support.V4.App.Fragment
. The following code is what I use to show the DialogFragment
:
Android.Support.V4.App.FragmentTransaction ft = FragmentManager.BeginTransaction();
PlaylistSettingsDialogFragment psdf = new PlaylistSettingsDialogFragment();
psdf.Show(ft, "PlaylistSettings");
I get a error from the last line. It says:
Cannot convert the first parameter(ft) from Android.Support.V4.App.FragmentTransaction to Android.App.FragmentManager
Show method for DialogFragment has 2 variants:
int Show(FragmentTransaction transaction, String tag)
or
void Show(FragmentManager manager, String tag)
so You can use it like this:
Android.Support.V4.App.FragmentTransaction ft = FragmentManager.BeginTransaction();
PlaylistSettingsDialogFragment psdf = new PlaylistSettingsDialogFragment();
var transactionId = psdf.Show(ft, "PlaylistSettings");
or
PlaylistSettingsDialogFragment psdf = new PlaylistSettingsDialogFragment();
psdf.Show(FragmentManager, "PlaylistSettings");
I usually use these lines of code to use Dialog Fragment in xamarin android i hope it helps!
FragmentTransaction fragmentTransaction = _activity.FragmentManager.BeginTransaction();
//remove fragment from backstack if any exists
Fragment fragmentPrev = _activity.FragmentManager.FindFragmentByTag(_activity.Resources.GetString(Resource.String.dialogfragment_tag_name));
if (fragmentPrev != null)
fragmentTransaction.Remove(fragmentPrev);
fragmentTransaction.AddToBackStack(null);
DialogFragmentFeedBackRating dialogFragment = DialogFragmentFeedBackRating.NewInstace(null,_activity);
dialogFragment.Show(fragmentTransaction, _activity.Resources.GetString(Resource.String.dialogfragment_tag_name));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.