As feared, even in onPrepareDialog(...), findViewById returns NULL. :( Request help.
-vignesh On Wed, May 20, 2009 at 8:12 AM, Vignesh <vignesh.kart...@gmail.com> wrote: > Sean, > > Thanks for your email. > > The layout contains a radiogroup with 3 radiobuttons and a > button(okButton). I have a onclicklistener for the button and when > onClickListener is triggered, I try to do findViewById(). Isn't the dialog > still not available?. > > Meanwhile, I shall try accesssing them in onPrepareDialog and let the > group. > > -Vignesh > > > On Tue, May 19, 2009 at 7:20 PM, Sean Hodges > <seanhodge...@googlemail.com>wrote: > >> >> Hello Vignesh, >> >> onCreateDialog() is invoked before the dialog is populated, so the >> RadioGroup widget has not yet been created. You probably want to >> override onPrepareDialog(). See these sections in the API: >> >> >> http://developer.android.com/reference/android/app/Activity.html#onCreateDialog%28int%29 >> >> http://developer.android.com/reference/android/app/Activity.html#onPrepareDialog%28int,%20android.app.Dialog%29 >> >> >> On Tue, May 19, 2009 at 2:38 PM, Vignesh <vignesh.kart...@gmail.com> >> wrote: >> > Hi, >> > >> > I am throwing up a dialog on a Buttonpress in my application. This >> dialog >> > sets the content from an xml layout and the layout has three radio >> buttons >> > within a radiogroup and then two buttons (Ok/Cancel). >> > >> > My intent is to know the radiobutton choosen by the user at the time of >> > pressing "Ok". >> > >> > Layout when_options look this way: >> > <RadioGroup >> > android:id="@+id/whenRadioGroup" >> > android:layout_width="fill_parent" >> > android:layout_height="wrap_content" >> > android:orientation="vertical"> >> > >> > <RadioButton android:id="@+id/time" >> > android:layout_width="wrap_content" >> > android:layout_height="wrap_content" >> > android:text="Time" /> >> > >> > <RadioButton android:id="@+id/incomingcall" >> > android:layout_width="wrap_content" >> > android:layout_height="wrap_content" >> > android:text="Incoming Call" /> >> > </RadioGroup> >> > >> > <Button android:id="@+id/ok_when" >> > android:layout_width="wrap_content" >> > </Button> >> > >> > protected Dialog onCreateDialog(int id) >> > { >> > Dialog d = new Dialog(screen1.this); >> > // On the new dialog, I set the above layout >> > d.setContentView(R.layout.when_options); >> > // finding the button with id ok_when >> > Button okButton = (Button) d.findViewById(R.id.ok_when); >> > // Setting listener for ok_when button >> > okButton.setOnClickListener(new Button.OnClickListener(){ >> > public void onClick(View v) >> > { >> > // Finding the radiogroup with name >> whenRadioGroup >> > RadioGroup whenRadioGroup = >> > (RadioGroup)findViewById(R.id.whenRadioGroup); <<<<<-----Returns >> NULL >> > d.dismiss(); >> > } >> > } >> > >> > Further, I also find these in R.java >> > >> > public static final class id { >> > ............................ >> > public static final int whenRadioGroup=0x7f05000d; >> > } >> > >> > >> > Kindly help me understand why findViewById returns NULL. >> > >> > Thanking in advance, >> > Vignesh >> > >> > > >> > >> >> >> >> > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---