using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Util; using Android.Views; using Android.Widget; namespace CommonLib { public delegate void DialogOK(); public class MessageBox : DialogFragment { public Activity parent; public string strTitle; public string strMessage; public string strOK; public string strCancel; public event DialogOK okEvent = null; public static MessageBox NewInstance(Bundle bundle) { MessageBox fragment = new MessageBox(); fragment.Arguments = bundle; return fragment; } public static MessageBox Execute(Activity parent, string strTitle, string strMessage, string strOK = "¿¹", string strCancel = "¾Æ´Ï¿À") { FragmentTransaction ft = parent.FragmentManager.BeginTransaction(); //Remove fragment else it will crash as it is already added to backstack Fragment prev = parent.FragmentManager.FindFragmentByTag("dialog"); if (prev != null) { ft.Remove(prev); } ft.AddToBackStack(null); // Create and show the dialog. MessageBox newFragment = MessageBox.NewInstance(null); newFragment.parent = parent; newFragment.strTitle = strTitle; newFragment.strMessage = strMessage; newFragment.strOK = strOK; newFragment.strCancel = strCancel; //Add fragment newFragment.Show(ft, "dialog"); return newFragment; } public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your fragment here } public override Dialog OnCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder alert = new AlertDialog.Builder(Activity); alert.SetTitle(this.strTitle); alert.SetMessage(this.strMessage); alert.SetPositiveButton(this.strOK, (senderAlert, args) => { if (this.okEvent != null) this.okEvent(); // Toast.MakeText(Activity, "Deleted!", ToastLength.Short).Show(); }); alert.SetNegativeButton(this.strCancel, (senderAlert, args) => { }); Dialog dialog = alert.Create(); dialog.Show(); return dialog; } } }