3つ以上のラジオボタンを持つradiogroupsを作成しますか?
-
24-12-2019 - |
質問
質問をして申請しようとしています。放射線地計でそれらを一緒に参加させる方法はありますか、それとも各ラジオボタンを個別に処理する必要がありますか?ラジオグループには3つのラジオボタンがありますが、ラジオボタンを3つ以上に増やすことができますか?もしそうなら、それでどのように?
解決
各コードから各RadioButtonを入手できます。
RadioGroup rg = (RadioGroup )findViewById(R.id.radio_group);
RadioButton r1 = (RadioButton) rg.getChildAt(0);
RadioButton r2 = (RadioButton) rg.getChildAt(1);
RadioButton r3 = (RadioButton) rg.getChildAt(2);
RadioButton r4 = (RadioButton) rg.getChildAt(3);
.
YESラジオグループの3ラジオボタンを追加することができます
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
. 他のヒント
ラジオボタンをradiogroupに追加してからレイアウトへの放射線地計に追加する必要があります。
final RadioButton[] rb = new RadioButton[4];
RadioGroup rg = new RadioGroup(this); //create the RadioGroup
rg.setOrientation(RadioGroup.HORIZONTAL);//or RadioGroup.VERTICAL
for(int i=0; i<4; i++){
rb[i] = new RadioButton(this);
rg.addView(rb[i]); //the RadioButtons are added to the radioGroup instead of the layout
rb[i].setText("Test");
}
ll.addView(rg);//you add the whole RadioGroup to the layout
ll.addView(submit);
.
編集:
またはXMLにRadioGroupを定義するだけです。
<TableRow>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/radiobuttons">
</RadioGroup>
</TableRow>
.
でプログラムで追加のボタンを追加します。
RadioGroup rg = (RadioGroup) findViewById(R.id.radiobuttons);//not this RadioGroup rg = new RadioGroup(this);
rg.setOrientation(RadioGroup.HORIZONTAL);//or RadioGroup.VERTICAL
for(int i=0; i<4; i++)
{
rb[i] = new RadioButton(this);
rg.addView(rb[i]);
rb[i].setText("Test");
}
. 所属していません StackOverflow