2

I have One Spinner in AlertDialog. On First look their will be only on spinner, and three options in it:

  1. Add Text Area,
  2. Add Edit Text,
  3. Add Radio Button.

WHen user will select any one option in the sipnner, AlerDialog should disply Text Area/Edit Text/Radio in the AlertDialog under the Spinner.

Any help/links

Thanks

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
ALi
  • 430
  • 7
  • 19

3 Answers3

1

Create Layout what you want and set it alertDialog.setContenView(R.layout.alertdialg);

Samir Mangroliya
  • 39,918
  • 16
  • 117
  • 134
1

You can make a layout with Text, Radio and etc. Set the property Visibility = GONE for them. After selecting a value from spinner, set the required fields property Visibility = VISIBLE.

Vyacheslav Shylkin
  • 9,741
  • 5
  • 39
  • 34
1

Create the XML Layout view with your spinner and the text, edit text, and radio button. You Set the visibility of your text, edit text, and radio button to GONE.

I think the easiest way to do this is to extend the AlertDialog object. In the object you can set the view of you AlertDialog using

this.setContentView(R.layout.yourLayout);

Now you can get references to your elements using

(EditText) editText = (EditText) this.findViewById(R.id.editTextIdOnLayout);

Add a listener to you spinner and based on the options that is chose you can now use your element handles to change the visibility of what you want to show.

jjNford
  • 5,170
  • 7
  • 40
  • 64
  • Hi, I have try and mostly done, but onClick of Spinner is not working, How can i refresh alertDialog when spinner seletion changed. – ALi Mar 15 '12 at 13:51
  • I'm sure that the spinners view is refreshed by the spinner object. You should be adding the spinners events in the alertdialog object's constructor or a method that is guaranteed to be run. At that point you should be handling the spinner how u normally do. – jjNford Mar 15 '12 at 14:26
  • I'm not to familiar with spinners as i don't use them much but I think you want to use the onItemselectedListener(). Take a look at this http://stackoverflow.com/questions/1337424/android-spinner-get-the-selected-item-change-event – jjNford Mar 15 '12 at 14:30
  • When an item is selected you can change the visibly of your elements. – jjNford Mar 15 '12 at 14:30
  • Ahan, Great, Thanks jjNford.. :) – ALi Mar 15 '12 at 14:40