天天看點

Android單選框

1、添加布局

<RadioGroup
    android:id="@+id/radiogroup1"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:orientation="vertical">

    <RadioButton
        android:id="@+id/radiobutton1"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:text="是" />

    <RadioButton
        android:id="@+id/radiobutton2"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:text="否" />

</RadioGroup>
           

2、擷取控件

@BindView(R.id.radiobutton1)
RadioButton radioButton1;

@BindView(R.id.radiobutton2)
RadioButton radioButton2;
           

3、擷取單選控件狀态

if(radioButton1.isChecked())
     healthReport.setOption("1");
else
     healthReport.setOption("2");
           

這是單選框的常用功能,通過其他控件觸發,擷取單選框選擇結果。

雖然是一個非常簡單的應用,儲存模闆友善以後使用