Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between Dialog.setContentView( View ) & AlertDialog.setView( View )

I'm working on creating a custom dialog to get input from the user. I've noticed that when I use an AlertDialog I can add widgets such as an EditText to the AlertDialog using setView() method. I'm looking into customizing AlertDialog and noticed that Dialog has a method setContentView(). In the subclass of AlertDialog I could use either setContentView() or setView().

One difference I've noticed is when I use setView() on an AlertDialog, I can see Positive & Negative buttons. In my subclass of AlertDialog, using setContentView() I don't get the Positive & Negative buttons.

Can anyone explain other differences?

Thanks.

like image 671
kralvarado Avatar asked May 18 '11 06:05

kralvarado


People also ask

What's the difference between dialog and AlertDialog in Android?

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 .

What is the difference between dialog and dialog fragment?

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 are the dialog classes in Android?

There are three kinds of lists available with the AlertDialog APIs: A traditional single-choice list. A persistent single-choice list (radio buttons) A persistent multiple-choice list (checkboxes)


1 Answers

If I undesrstood it correctly, setContentView inflates the entire Dialog window with your custom layout. Title, icon, buttons... nothing remains. setView on the other hand sets the layout of the view between the buttons and the title.

See image

like image 127
Maggie Avatar answered Oct 07 '22 17:10

Maggie