Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display MessageBox in Monodroid

How can I display a message box in Xamarin.Android? How can I get the yes or no response from the message box?

--- Updated :

myBtn.Click += (sender, e) => 
{
   new AlertDialog.Builder(this)
   .SetMessage("hi")
   .Show();
};
like image 306
MilkBottle Avatar asked May 21 '13 01:05

MilkBottle


People also ask

How do I view MessageBox?

To display a message box, call the static method MessageBox. Show. The title, message, buttons, and icons displayed in the message box are determined by parameters that you pass to this method.

What is message box in C#?

MessageBox is a class in C# and Show is a method that displays a message in a small window in the center of the Form. MessageBox is used to provide confirmations of a task being done or to provide warnings before a task is done. Create a Windows Forms app in Visual Studio and add a button on it.


2 Answers

Try this:

public void ShowAlert (string str)
        {
            AlertDialog.Builder alert = new AlertDialog.Builder (this);
            alert.SetTitle (str);
            alert.SetPositiveButton ("OK", (senderAlert, args) => {
                // write your own set of instructions
                });

            //run the alert in UI thread to display in the screen
            RunOnUiThread (() => {
                alert.Show ();
            });
        }
like image 93
Ram Ch. Bachkheti Avatar answered Oct 31 '22 12:10

Ram Ch. Bachkheti


You can use the AlertDialog.Buider class from within an Activity.

new AlertDialog.Builder(this)
    .SetPositiveButton("Yes", (sender, args) =>
    {
        // User pressed yes
    })
    .SetNegativeButton("No", (sender, args) =>
    {
        // User pressed no 
    })
    .SetMessage("An error happened!")
    .SetTitle("Error")
    .Show();
like image 38
Alex Wiese Avatar answered Oct 31 '22 11:10

Alex Wiese