Android的RadioGroup中checkedButton财产 [英] Android RadioGroup checkedButton property

查看:588
本文介绍了Android的RadioGroup中checkedButton财产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在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

这篇关于Android的RadioGroup中checkedButton财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆