Android的RadioGroup中checkedButton财产财产、Android、RadioGroup、checkedButton

2023-09-06 03:12:21 作者:我愿用十年换你天真无邪

我想在Android中有一个单选按钮默认为选中打造RadioGroup中。我不知道这是可以做到通过XML,而不是编程。 下面code段似乎并没有工作,我发现了一个错误

I am trying to build RadioGroup in Android with one RadioButton checked by default. I'm wondering if this is possible to do through xml, rather than programmatically. The following code snippet doesn't seem to work as I'm getting an error

错误:错误:未发现的资源匹配给定名称(在'checkedButton,值为@ ID / rdb_positive')

error: Error: No resource found that matches the given name (at 'checkedButton' with value '@id/rdb_positive').

<RadioGroup
    style="@style/FormInputField"
    android:orientation="vertical"
    android:checkedButton="@id/rdb_positive"> <!-- Error on this line -->
    <RadioButton
        android:id="@+id/rdb_positive"
        android:text="@string/answer_positive" />
    <RadioButton
        android:id="@+id/rdb_negative"
        android:text="@string/answer_negative" />
</RadioGroup>

这有一定道理的方式,为单选按钮的id是定义在RadioGroup中的属性设置后,但我不知道为什么会有这样的属性可用。

It does make sense in a way, as the id of the RadioButton is defined after the attribute in the RadioGroup is set, but then I wonder why there is such attribute available.

任何帮助是极大AP preciated

Any help is greatly appreciated

由于事先

推荐答案

使用安卓checkedButton =@ + ID / rdb_positive,我想你添加 + 签那么它的作品

Use android:checkedButton="@+id/rdb_positive" ,i think you add + sign then its works