2017-02-15 39 views
0

我在RadioGroup上遇到了一些麻烦。出于某种原因,它无法找到我的RadioButton中的一个的ID。找不到与RadioGroup名称相匹配的资源

错误:

Error:(18, 32) No resource found that matches the given name (at 'checkedButton' with value '@id/euro1'). 

我的代码:

<RadioGroup 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/betGroup" 
    android:checkedButton="@id/euro1"> 

    <RadioButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/euro1" 
     android:drawableLeft="@drawable/euromoent1" 
     android:layout_marginBottom="10dp"/> 

    <RadioButton 
     android:drawableLeft="@drawable/euromoent2" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:id="@+id/euro2" 
     android:layout_marginBottom="10dp"/> 

    <RadioButton 
     android:drawableLeft="@drawable/euro5small" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:id="@+id/euro5" 
     android:layout_marginBottom="10dp"/> 

    <RadioButton 
     android:drawableLeft="@drawable/euro10small" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:id="@+id/euro10" 
     android:layout_marginBottom="10dp"/> 

    <RadioButton 
     android:drawableLeft="@drawable/euro20small" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:id="@+id/euro20" /> 

</RadioGroup> 

所以这是给我的errror线路:

android:checkedButton="@id/euro1"> 

即使单选按钮下方有一个确切的ID。我究竟做错了什么?谢谢。

回答

0

您无法在无线电组上使用android:checkedButton="@id/euro1">

android:checked="false"添加到您的每个RadioButton。无论您要检查,添加android:checked="true"

像检查按钮:

<RadioButton 
    android:drawableLeft="@drawable/euro5small" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:id="@+id/euro5" 
    android:checked="true" 
    android:layout_marginBottom="10dp"/> 

对于未选中按钮:

<RadioButton 
    android:drawableLeft="@drawable/euro5small" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:id="@+id/euro5" 
    android:checked="false" 
    android:layout_marginBottom="10dp"/> 

从RadioGroup中删除android:checkedButton="@id/euro1">

希望它可以帮助

+0

谢谢。我最终通过在id中添加一个加号来解决问题,如下所示:android:checkedButton =“@ + id/euro1”。我想你的工作也会如此! – Jesper

相关问题