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();
};
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();
};
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();
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 ();
});
}