5

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?

Sufian
  • 5,997
  • 14
  • 60
  • 111
quartz
  • 59
  • 1
  • 6
  • Possible duplicate of [Custom Layout for DialogFragment OnCreateView vs. OnCreateDialog](http://stackoverflow.com/questions/13257038/custom-layout-for-dialogfragment-oncreateview-vs-oncreatedialog) – Mani Jun 28 '16 at 07:16

1 Answers1

5

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.

Raaja SN
  • 272
  • 2
  • 14
  • Thank you!! This is very helpful. – quartz Jul 28 '16 at 05:46
  • There are some problem with list performance depending on which method you use: http://stackoverflow.com/questions/41515730/dialogfragment-recyclerview-swap-animation-lags-depending-on-the-method-used-t – AppiDevo Jan 08 '17 at 11:36