It's a "feechur" -- likely the code doesn't test whether a button is checked or not as it's added to the group, so it doesn't know the first button's checked and thus allows another to be checked. Poor design, but the implementation is the specification here (since there's no other specification), so you can't really say it's wrong.
On Sep 15, 10:15 am, Christophe <[email protected]> wrote: > > There seems to be a problem, if you try to set the checked option, > > before adding it to the RadioGroup. If you set it after adding it, > > that works fine... > > Yes ! It works fine now ! > A bug in android ? :) > > thanks for you help > > On Sep 15, 4:44 pm, Kumar Bibek <[email protected]> wrote: > > > @Treking, > > > You will have to create new Radiobuttons each time, else, you will not > > be able to add it to the RadioGroup. It will say, the child already > > has a parent. So, if you want to display multiple radio buttons like > > this, then, you have to create new ones, i.e, you cannot reuse that. > > > There seems to be a problem, if you try to set the checked option, > > before adding it to the RadioGroup. If you set it after adding it, > > that works fine... > > > Here's the code. > > > RadioGroup rg = (RadioGroup) findViewById(R.id.RadioGroup01); > > for (int i = 0; i < 6; i++) { > > rg.addView(getRadioButton(i)); > > } > > > ((RadioButton)rg.getChildAt(0)).setChecked(true); > > > private RadioButton getRadioButton(int index) { > > RadioButton rb = new RadioButton(this); > > rb.setText("Radio " + index); > > return rb; > > } > > > -Kumar Bibekhttp://techdroid.kbeanie.com > > > On Sep 15, 6:42 pm, TreKing <[email protected]> wrote: > > > > On Wed, Sep 15, 2010 at 8:35 AM, Christophe < > > > > [email protected]> wrote: > > > > > 1 - Your getRadioButton function returns a new RadioButton. > > > > > since I want 10 different radio buttons in my group, I can reuse the > > > > same radio button ?!? > > > > The code you posted adds 10 RBs to a group. Then your get function > > > returns a > > > new one that's not associated with anything. How do you expect that to > > > work? > > > You're basically saying, "when getting a Radio Button, instead of getting > > > one I already created, make a new one and if was trying to get the first > > > one, set it to checked. Also, don't associate it with a group so its > > > checked > > > state won't effect others." > > > > > > 2 - You're using getApplicationContext(). > > > > > I have try with just "this" instead of "getApplicationContext()", but > > > > the > > > > problem is still there > > > > This won't fix your problem (see #1), but you should avoid > > > getApplicationContext(). It will cause you problems elsewhere. > > > > Should I use something else ? > > > > Your most local Context ... usually "this". > > > > On Wed, Sep 15, 2010 at 8:38 AM, Kumar Bibek <[email protected]> wrote: > > > > 1. New Radio button: I dont see a problem with that. > > > > He already created 10 and the "new" ones don't get added to the group. > > > > ------------------------------------------------------------------------------------------------- > > > TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago > > > transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

