AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.SetMessage("Are you sure you want to delete this item?") .SetCancelable(false) .SetNegativeButton("Cancel", (senderAlert, args) => { // Do something when negative button is clicked }) .SetPositiveButton("Yes", (senderAlert, args) => { // Do something when positive button is clicked }); AlertDialog alertDialog = builder.Create(); alertDialog.Show();
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetTitle("Select your favorite color") .SetItems(colorsArray, (senderAlert, args) => { string selectedColor = colorsArray[args.Which]; // Do something with the selected color }) .SetNegativeButton("Cancel", (senderAlert, args) => { // Do something when negative button is clicked }); AlertDialog alertDialog = builder.Create(); alertDialog.Show();This example creates an alert dialog that prompts the user to select their favorite color from a list. The dialog includes a "Cancel" button that does nothing, and a listener that retrieves the selected color and triggers an action. Package library for this example: Android.App.