Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between AlertDialog.builder's obj.create() vs obj.show() vs obj.create().show()

Is there any difference between .create() and .show() methods of AlertDialog's builder class? Like when we create an alert dialog using:

AlertDialog.Builder builder = new 
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("");
builder.setPositiveButton(....)
builder.setNegativeButton(....)

What is recommended pratice to use and why?

builder.create() //I have seen this creates and displays the dialog

OR

builder.show() //this also displays the dialog

OR

builder.create().show() //well same thing

I have read the documentation. But was unable to make any sense from it. Any ideas ?

like image 233
drulabs Avatar asked May 23 '12 10:05

drulabs


People also ask

What is AlertDialog builder?

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. Android Alert Dialog is built with the use of three fields: Title, Message area, Action Button.

What is the use of AlertDialog?

AlertDialog. A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout. DatePickerDialog or TimePickerDialog. A dialog with a pre-defined UI that allows the user to select a date or time.

Which method is used to set the list in AlertDialog in android?

The way to make a checkbox list is to use setMultiChoiceItems . // setup the alert builder AlertDialog. Builder builder = new AlertDialog. Builder(context); builder.

What is the difference between dialog and 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.


1 Answers

obj.create()-For create Dialog

obj.show()-For show Dialog <- without it you cant show dialog if you created.

and

obj.create().show()-create and show Dialog i mean both same as above two in one statement.

like image 83
Samir Mangroliya Avatar answered Sep 28 '22 06:09

Samir Mangroliya