Quick Tips : Displaying an Alert in Android using MonoDroid

Displaying an informational alert on screen

Let’s just display a quick informative popup, which will only display an alert on screen with a title and a message in it. It actually gets closed when the back button get touched.


Let’s display the OK and Cancel button

We will add OK and Canel button. On click of the buttons, it will display a quick Toast message on screen in order
to differentiate which button is clicked.


Let’s add Back button restriction here

Let’s ensure the alert only disappears on the OK or Cancel click, not on back button press.

The line alert.SetCancelable(false); prevents the back button to close the alert dialog. So user has to click any of the buttons in order to close the dialog.

Choose from a list of items in dialog

This alert will show a lost of items to choose. On choosing an item, it will display a toast message, which item is chosen.


Hope this will help 🙂

Categories: Android, CSharp, MonoDroid, Visual Studio, Xamarin

1 comment

Leave a Reply

%d bloggers like this: