创建单选组时,我在其中插入了 3 个单选按钮,并且在执行代码并检查第二个单选按钮时默认选中第一个按钮,例如第一个按钮仍处于选中状态。
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/radg">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/agimmob"
android:textColor="@color/welcomecolor"
android:textSize="20dp"
android:layout_marginLeft="45dp"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/prop"
android:textColor="@color/welcomecolor"
android:textSize="20dp"
android:layout_marginLeft="45dp"
android:checked="true"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/achet"
android:textColor="@color/welcomecolor"
android:textSize="20dp"
android:layout_marginLeft="45dp"/>
</RadioGroup>
我尝试默认检查第二个,但我遇到了同样的问题
您必须使用 RadioGroup 组件中的 checkedButton 属性,并将默认情况下要检查的 radioButton 的 id 传递给该属性
<RadioGroup
android:id="@+id/radg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkedButton="@id/rb1">
没有必要使用radioRuttons上的checked属性