您好大家 我要如何驗證我的形式專門針對「性別」,在那裏我已經使用單選,這樣當「男性」選擇「女性」將自動獲得未選中。再次,我將不得不採取單選或者它會更好地利用RadioGroup中? 謝謝。如何驗證android中性別的單選按鈕?
1
A
回答
3
把你的性別RadioButton
個RadioGroup
1
使用RadioGroup中內。 你可以看到完整的文檔RadioGroup
您可以從developer.android.com參考示例 - >http://developer.android.com/resources/tutorials/views/hello-formstuff.html#RadioButtons
例如XML文件:
<RadioGroup android:layout_height="wrap_content" android:id="@+id/gender_group"
android:layout_width="match_parent">
<RadioButton android:text="Male"
android:layout_width="wrap_content" android:id="@+id/radio0"
android:layout_height="wrap_content" android:checked="true"></RadioButton>
<RadioButton android:text="Female"
android:layout_width="wrap_content" android:id="@+id/radio1"
android:layout_height="wrap_content"></RadioButton>
</RadioGroup>
0
試試這個
public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.radio_pirates:
if (checked)
// Pirates are the best
break;
case R.id.radio_ninjas:
if (checked)
// Ninjas rule
break;
}
}
相關問題
- 1. 在android中驗證單選按鈕
- 2. 如何驗證laravel 5.4單選按鈕?
- 3. 如何驗證單選按鈕組SimpleSchema
- 4. 如何驗證離子單選按鈕
- 5. jquery驗證單選按鈕
- 6. 驗證單選按鈕
- 7. formvalidation單選按鈕驗證
- 8. 單選按鈕驗證:javascript
- 9. 驗證單選按鈕
- 10. jquery驗證單選按鈕
- 11. 驗證單選按鈕組
- 12. 單選按鈕驗證
- 13. 驗證單選按鈕
- 14. jquery單選按鈕驗證
- 15. 在cakephp中單選按鈕的驗證
- 16. WinForms中的單選按鈕驗證
- 17. 如何驗證單選按鈕組?在柔性
- 18. jQuery表單驗證對於單選按鈕或單選按鈕
- 19. 如何檢查硒webdriver中的性別選擇單選按鈕?
- 20. 驗證:當選中並驗證時顯示單選按鈕
- 21. 如何驗證單選按鈕被選中?
- 22. Javascript +單選按鈕/複選框驗證
- 23. 驗證表單與單選按鈕
- 24. 的Javascript:驗證單選按鈕
- 25. 單選按鈕的Javascript驗證
- 26. jQuery驗證組的單選按鈕
- 27. javascript驗證單選按鈕的形式
- 28. 如何驗證循環中的textarea和單選按鈕
- 29. 如何驗證react.js中的單選按鈕?
- 30. 如何修復jQuery插件中的單選按鈕驗證?
爲什麼海盜和忍者? – dove 2013-02-19 11:53:49
它從官方文檔是 - [見這裏](http://developer.android.com/guide/topics/ui/controls/radiobutton.html#HandlingEvents) – 2015-05-12 10:00:18