android - set two radio buttons in one row then next two radio is on second row and so on -


i want set 2 two radiobuttons 1 row , next 2 radiobuttons on second row dynamically(programmatically) new android body have idea or sample code of it. have is:

radiogroup radiogroup = (radiogroup)findviewbyid(r.id.radiogroup01); for(int i=0;i<10;i++) {     radiobutton rdbtn = new radiobutton(this);     rdbtn.setid(i);     rdbtn.settext("test");      linearlayout ll = new linearlayout(this);     ll.setorientation(linearlayout.horizontal);      ll.addview(rdbtn);     radiogroup.addview(rdbtn);     ll.addview(radiogroup);     //i%2 == 0 } 

you can use below code:

activity code:

protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          for(int row=0; row < 5; row++)           {             linearlayout ll = new linearlayout(this);             ll.setorientation(linearlayout.horizontal);             for(int = 0; < 2; i++) {                 radiobutton rdbtn = new radiobutton(this);                 rdbtn.setid((row * 2) + i);                 rdbtn.settext("test " + rdbtn.getid());                 ll.addview(rdbtn);             }             ((viewgroup)findviewbyid(r.id.radiogroup)).addview(ll);          }     } 

activity_main.xml:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".mainactivity" >      <radiogroup         android:id="@+id/radiogroup"         android:orientation="vertical"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerhorizontal="true"         android:layout_centervertical="true"/>  </relativelayout> 

output on screen:

enter image description here hope looking for. cheers!


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -