Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Dialog and AlertDialog?

Tags:

android

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?

like image 415
Hiva Avatar asked Nov 17 '18 07:11

Hiva


People also ask

What is the difference between dialog & DialogFragment?

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.

What is the use of alert dialog?

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.

What is AlertDialog builder?

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.


2 Answers

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...)

enter image description here

when would i use a Dialog?

-When i want to carry on a complex process with more buttons and widgets .

-Example:

enter image description here

like image 141
Hissaan Ali Avatar answered Oct 24 '22 23:10

Hissaan Ali


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.

like image 42
Ramesh Yankati Avatar answered Oct 24 '22 22:10

Ramesh Yankati