2014-02-18 25 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

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