2016-05-24 16 views
0

こんにちは私は2つのラジオボタンを持っています。私はラジオグループを動的に追加する必要があります。 これを行う方法は? これは私のxmlです、あなたはそれがのLinearLayoutで追加したい魔女でレイアウトを想定すると感謝動的にラジオグループを追加しますが、ラジオボタンはxmlです

    <RadioButton 
         android:id="@+id/radiotwo" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:checked="false" 
         android:text="b" 
         android:textSize="23dp" /> 
        <RadioButton 
         android:id="@+id/radioone" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:checked="false" 
         android:text="a" 
         android:textSize="23dp" /> 
+0

を使用すると、ラジオ・グループを追加しない理由ラジオボタン全体が動的になりますか? –

答えて

0

は、あなたがこのようにラジオボタンを追加することができます。

LinearLayout myLayout = findViewById(R.id.main); 
RadioButton myButton = new RadioButton(this); 
myButton.setLayoutParams(new LinearLayout.LayoutParams(
           LinearLayout.LayoutParams.FILL_PARENT, 
           LinearLayout.LayoutParams.FILL_PARENT)); 
myLayout.addView(myButton); 
関連する問題