views:

313

answers:

2

I have a button that pops up with a dialog box on click.

I want the dialog box to have an EditText and a Spinner inside the dialog box.

I don't know how I'd set the view for it, I have the code for an AlertDialog and it works, it's just the EditText and Spinner that I need to place inside it then I can get on with the rest of the app's code.

Please can someone show me how I'd add an EditText and Spinner please?

+3  A: 

Two options I can think of:

1) Use AlertDialog's setView method.

2) Create an Activity with

android:theme="@android:style/Theme.Dialog"

in your AndroidManifest.

Number one should be easier to do while number two will give you more flexibility.

Macarse
What would I put inside the setView?I've tried "R.layout.newfiledialog" but that doesn't work :(I'm only a beginner!
AlexPriceAP
`R.layout.newfiledialog` is just an int. you should inflate that view with an inflator.
Macarse
Thank you SO much. I've been scratching my head at this for ages! :)
AlexPriceAP
+1  A: 

You can create your own customdialog. Declare your views in a layout and load it with the help of AlertDialog like the one mentioned in the sample

http://developer.android.com/intl/de/guide/topics/ui/dialogs.html#CustomDialog

Rahul
Thanks for your help!
AlexPriceAP