I'm creating a dynamic dialog box in xamarin.android
and I want the dialog box to receive a function that it will execute upon clicking the action button.
Heres my code:
public static void ShowDialogBox(Context context, Function dynamicFunction)
{
Dialog popupDialog = new Dialog(context);
popupDialog.SetContentView(Resource.Layout.dialog_dynamic);
popupDialog.Window.SetSoftInputMode(SoftInput.AdjustResize);
popupDialog.Window.SetBackgroundDrawableResource(Android.Resource.Color.Transparent);
popupDialog.Show();
TextView title = popupDialog.FindViewById<TextView>(Resource.Id.dialog_title);
TextView content = popupDialog.FindViewById<TextView>(Resource.Id.dialog_content);
ImageView icon = popupDialog.FindViewById<ImageView>(Resource.Id.dialog_icon);
Button actionButton = popupDialog.FindViewById<Button>(Resource.Id.dialog_action_button);
popupDialog.FindViewById<ImageButton>(Resource.Id.dialog_close).Click += delegate { popupDialog.Dismiss(); };
popupDialog.FindViewById<Button>(Resource.Id.dialog_cancel_button).Click += delegate { popupDialog.Dismiss(); };
actionButton.Click += dynamicFunction;
}
*Take note that the Function parameter is just an example. Also I will make the text and content in this dialog box a parameter.
Example scenario:
- If I send GetCurrentDate function to this dialog box, when the action button is clicked it will get the current date.
- If I send OpenBluetooth function to this dialog box, when the action button is clicked it will open the Bluetooth
It is possible to send another function to this ShowDialogBox
function and run it when the action button is clicked? My purpose here it to make my code clean and easy to use.