3

RadioGroup内にRadioButtonがあります。

ボタンの初期状態を設定すると問題が発生します

android:checked = "true"

RadioButton "F"を押しても、RadioButton"M"のチェックが外れないためです。

どのようにできるのか?なにが問題ですか?

コードは次のとおりです。

<RadioGroup
   android:id="@+id/registrazione_utente_sesso"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="horizontal" >

   <RadioButton
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:checked="true"
      android:text="M"
      android:textColor="#ff7415"
      android:textSize="18sp" />

   <RadioButton
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="13.33dp"
      android:text="F"
      android:textColor="#ff7415"
      android:textSize="18sp" />
</RadioGroup>

画面:

初期状態(正しい):

http://i.imgur.com/YsUIg.png

RadioButton "F"を押したときの最終状態(間違っている):

http://i.imgur.com/YJms9.png

ありがとう

4

1 に答える 1

5

android:id を使用してラジオ ボタンに一意の ID を割り当て、RadioGroup の android:checkedButton 属性を次のように設定します。

<RadioGroup
   android:id="@+id/registrazione_utente_sesso"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="horizontal"
   android:checkedButton="@+id/radiobutton_m" >

   <RadioButton
      android:id="@+id/radiobutton_m"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="M"
      android:textColor="#ff7415"
      android:textSize="18sp" />

   <RadioButton
      android:id="@+id/radiobutton_f"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="13.33dp"
      android:text="F"
      android:textColor="#ff7415"
      android:textSize="18sp" />
</RadioGroup>
于 2012-07-16T13:26:01.150 に答える