I know that the Dialog
class is the base class for dialogs, but it says in the documentation that you should avoid instantiating Dialog
directly. Instead, you should use one of the following subclasses: AlertDialog
or DatePickerDialog
or TimePickerDialog
.
Why?
Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.
Alert Dialog shows the Alert message and gives the answer in the form of yes or no. Alert Dialog displays the message to warn you and then according to your response, the next step is processed.
Set a list of items to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener. AlertDialog.Builder. setNegativeButton(CharSequence text, DialogInterface.OnClickListener listener) Set a listener to be invoked when the negative button of the dialog is pressed.
AlertDialog is a lightweight version of a Dialog. This is supposed to deal with INFORMATIVE matters only, That's the reason why complex interactions with the user are limited. Dialog on the other hand is able to do even more complex things .
when would i use an Alert Dialog?
-When i just want to inform something to the user .
-When we want use for a prompt like Do you want to go back (Yes, No, Cancel. Alert dialog comes with 3 buttons which are positive, negative and neutral which are provided by default).
-When i want to prompt user for a simple value (number/date/string...)
when would i use a Dialog?
-When i want to carry on a complex process with more buttons and widgets .
-Example:
Dialogs in Android are used to shows alerts for making decisions or to edit a single value. But there are some differences between an AlertDialog and a Dialog. In an AlertDialog you always want to show a message and at least one Button for user interaction. In a Dialog you have a custom view to a TextView or something more complex.
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