2017-02-15 109 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

相關問題