Reputation:
What is the main difference between creating an AlertDialog and then showing and showing the AlertDialog.Builder itself?
For example. I can have a AlertDialog.Builder like this:
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
dialogBuilder.setTitle("title");
dialogBuilder.setMessage("message");
dialogBuilder.setPositiveButton("OK", null);
And I can show it in two ways:
Just showing the builder
dialogBuilder.show();
or create an AlertDialog from the builder and then show it
AlertDialog dialog = dialogBuilder.create();
dialog.show();
Upvotes: 2
Views: 2971
Reputation: 3574
Both does the same thing internally
dialogBuilder.show()
this will create a dialog and call show()
on the dialog as below
public AlertDialog show() {
final AlertDialog dialog = create();
dialog.show();
return dialog;
}
whereas dialog.show()
directly invokes show()
method of dialog since dialog is already created
Upvotes: 1
Reputation: 24
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.
and you can also reffer android.com/guide/topics/ui/dialogs
Upvotes: 0