2014-02-18 24 views
-1

我在我的Android应用程序的页面上有几个单选按钮,我想知道是否有人知道如何限制用户的选择只有一个单选按钮。Android应用程序中单选按钮的单选

在此先感谢。

+3

使用[RadioGroup中](http://developer.android.com/reference/android/widget/RadioGroup.html),在该用户只能选择一个单选按钮 –

+0

http://developer.android。 com/reference/android/widget/RadioGroup.html – peshkira

回答

1

确保你的单选按钮都在收音机组内。它应该只允许选择一个值。例如:

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

     <RadioButton 
      android:id="@+id/radioMale" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/radio_male" 
      android:checked="true" /> 

     <RadioButton 
      android:id="@+id/radioFemale" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/radio_female" /> 

    </RadioGroup> 
+1

非常感谢你,完美的工作 –