0

次のような Android レイアウトを設計しようとしています。

Entity1
option1 for Entity1
option2
...
optionN
Entity2
option1 for Entity2
...
optionN
Entity3

...

各エンティティに対して、1 つのオプションのみが許可されるという要件があります。

そして、それを強制するために RadioGroup を使用するつもりで、ラジオ ボタンを使用することにしました。上記を実現するために、次のように設計しました。

<table layout>
    <TextView, content = "Entity1"/>
    <TextView, content = "option1 for Entity1"/> <RadioButton/>
    <TextView, content = "option2"> <RadioButton/>
   ...
</table layout>

疑似コードは次のようになります。

 RadioGroup raGroup = createEmptyRaGroup()
    ...
    row = new TableRow(); 
    row.add(TextView-entity1);  
    row.add(TextView-op1ForEntity1); 
    RadioButtton raBtn = createRadioButton(); 
    raGroup.addView(raBtn); 
    row.addView(raBtn);  
    ...

そして、私が抱えている問題は、ラジオボタンを 1 つの RadioGroup の下にグループ化できないため、1 つのオプションのみが選択されることです。実行時に、Android は、ラジオ ボタンが行の直接の子である必要があると不平を言います。最初にラジオ ボタンを行に追加すると、最初にラジオ ボタンをラジオ グループに追加すると、同様の実行時エラーがスローされます。

上記のデザインなどを使用して RadioGroup 効果を実現する方法を教えてもらえますか?

みんなありがとう。

4

1 に答える 1

2

次のように、レイアウト内で RadioGroup を使用しないのはなぜですか。

<RadioGroup
    android:id="@+id/RadioGroup01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

<RadioButton 
    android:text="Choice 1"
    android:id="@+id/RadioButton01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

<RadioButton
    android:text="Choice 2"
    android:id="@+id/RadioButton02" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/>
</RadioGroup>
于 2010-08-07T03:06:10.997 に答える