SRam
SRam

Reputation: 2830

Need to Dynamically Set Radio Button horizontaly in a layout :android

I need to set the radio button dynamically in layout , but when i am adding it horizontally then it would be able to display radio button in a single row so my all radio button are not visible , i need to set rest radio button below to above radio button , means All button should be visible in Horizontally with text besides Left hand side of Radio button.. my code is below , but it showing radio button in a single row so all radio button are not visible..

main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Choose Your Favorite Actress" >
</TextView>

<RadioGroup
    android:id="@+id/RadioGroup01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
</RadioGroup>
<Button
    android:id="@+id/Button01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Submit" >
</Button>

 </LinearLayout>

and java class is :

 @Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    DisplayRadioButton();

}


public void DisplayRadioButton()
{
    for(int i=0;i<10;i++)
    {
        RadioGroup radiogroup = (RadioGroup)findViewById(R.id.RadioGroup01);
        RadioButton rdbtn = new RadioButton(this);
        rdbtn.setId(i);
        rdbtn.setText(text[i]);
        radiogroup.addView(rdbtn);
    }

}

Upvotes: 0

Views: 314

Answers (1)

abhijeet kokane
abhijeet kokane

Reputation: 7

radgroup.layout(l, t, r, b); left top right bottom positions

Upvotes: 1

Related Questions