I would like to create a home screen with a login button, which when clicked, opens a dialog box to enter a password and then either submit or cancelled.
I have read that there are two methods to do this in order to create a DialogFragment
- using onCreateDialog()
and onCreateView()
.
What is the difference between these two options, and which one is used in which scenarios?
The onCreateDialog()
is for displaying Basic Dialog. This is the simplest way to display a dialog. While using this method you need to use the builder method of the inbuilt dialog like AlertDialog to build the dialog and listeners for positive and negative button and return a Dialog.
On the other hand OnCreateView()
you can return a view to be used as a dialog. You can use your own layout to build a dialog UI. Your own button and listen for them. In simple words your own Custom Dialog.
Also Note: You can even set a view to your built in Dialog like AlerDialog in onCreateDialog()
by calling setView() method. The onCreateView()
is used to build your dialog from your own layout. Which version should you use is entirely upto you. I hope it helps.