Thursday, 15 August 2013

java - All radio buttons are getting selected under a radio group, android -



java - All radio buttons are getting selected under a radio group, android -

i'm new android , have xml this:

<radiogroup android:id="@+id/cardradiogroup" android:layout_width="wrap_content" android:layout_height="45dp" android:layout_alignparentleft="true" android:layout_marginleft="35dp" android:layout_aligntop="@+id/cardedittext"> </radiogroup>

i'm tyring inflate xml using code generate many radio buttons want depending on info model.

the code utilize (which within loop) :

layoutinflater inflater = this.getlayoutinflater(); view currentview = inflater.inflate(r.layout.card_payment_content_node,null); radiogroup rg = (radiogroup) currentview.findviewbyid(r.id.cardradiogroup); radiobutton rb = new radiobutton(this); //set radiobutton properties rb.settext(entry.getkey()); rb.setid(++radiobuttonidcounter); rg.addview(rb); //add view parent.addview(currentview);

this working expected. problem can select many radio buttons @ time on device.

i'm not sure why happening. i'm making mistake?

thanks in advance.

all of buttons have same id. that's why deed uniformly.

you inflate layout once. you'd have add together buttons programmatically identifying cardradiogroup , looping in code, generating unique ids buttons.

to add together radio buttons group, utilize radiogroup.addview().

to create radio buttons, utilize 1 of constructors of radiobutton , set farther properties if required.

java android

No comments:

Post a Comment