Yes, I know there's AlertDialog.Builder, but I'm shocked to know how difficult (well, at least not programmer-friendly) to display a dialog in Android.
I used to be a .NET developer, and I'm wondering is there any Android-equivalent of the following?
if (MessageBox.Show("Sure?", "", MessageBoxButtons.YesNo) == DialogResult.Yes){
// Do something...
}
Asking a Person whether he wants to call or not Dialog..
Steve H's answer is spot on, but here's a bit more information: the reason that dialogs work the way they do is because dialogs in Android are asynchronous (execution does not stop when the dialog is displayed). Because of this, you have to use a callback to handle the user's selection.
Check out this question for a longer discussion between the differences in Android and .NET (as it relates to dialogs): Dialogs / AlertDialogs: How to "block execution" while dialog is up (.NET-style)
1.Create AlertDialog set message,title and Positive,Negative Button:
2.Now find both buttons on DialogInterface Click then setOnClickListener():
3.To Show Alertdialog:
Note: Don't forget Final Keyword with AlertDialog.
In Kotlin:
Thanks. I use the API Level 2 (Android 1.1) and instead of
BUTTON_POSITIVE
andBUTTON_NEGATIVE
i have to useBUTTON1
andBUTTON2
.