2012-07-16 48 views
3

取消我有一个单选按钮一个RadioGroup中内,的Android - 单选按钮不与初始选中状态

问题出现了,当我设置按钮

机器人的初始状态:检查=“真“

,因为如果我按单选按钮‘F’的单选按钮‘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

最终状态,当我按下单选按钮 “F”(错误):

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

感谢

+0

你,如果你想手动管理设置按钮的初始状态 – AkashG 2012-07-16 13:25:14

+0

你必须设置F检查比M unchecked – AkashG 2012-07-16 13:25:58

回答

5

分配一个唯一的ID来与Android的单选按钮:ID,然后设置了android:在RadioGroup中的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> 
+0

耶!它工作正常非常感谢!你真快! – Andrea 2012-07-16 13:31:58

+0

不客气:) – 2012-07-16 13:42:30