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();
};
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.
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.
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 ();
});
}
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With