2012-04-10 4 views
0

ich folgende Fehlermeldung erhalten (Zeile 19 // XXX im Code):ViewBinder Gussfehler mit Android 4.0

04-10 10: 35: 08,301: E/Android Runtime (12417): java. lang.ClassCastException: android.widget. 35:: 08,301: E/Android Runtime (12417): Textview nicht zu android.widget.CheckBox 04-10 Oktober gegossen werden bei ms.jung.andorid.caldavtodo.CalDavToDoViewBinder.setViewValue (CalDavToDoViewBinder.java:19)

Mein Code:

class CalDavToDoViewBinder implements SimpleCursorAdapter.ViewBinder { 

    public boolean setViewValue(View view, Cursor cursor, int columnIndex) { 
     int viewId = view.getId(); 

     if(viewId == R.id.checkBox) { 
       CheckBox cb = (CheckBox) view; //XXX 

       if(cursor.getInt(cursor.getColumnIndexOrThrow(CalDavToDoProvider.STATE)) == 1) 
       { 
        cb.setChecked(true); 
       } 
       else 
       { 
        cb.setChecked(false); 
       } 
       return true; 

     } 
     else if(viewId == R.id.colorBar) 
     { 

       int color = cursor.getInt(cursor.getColumnIndexOrThrow(CalDavToDoProvider.COLOR)); 

       TextView colorBar = (TextView)view; 
       colorBar.setBackgroundColor(color); 

       return true;  
     } 

     return false; 
    } 
} 

ich bin sehr verwirrt, weil R.id.checkBox ist definitiv ein CheckBox.

Edit:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rowLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="0dp" > 

    <TextView 
     android:id="@+id/colorBar" 
     android:layout_width="10dp" 
     android:layout_height="fill_parent" 
     android:background="@color/pink" 
     android:text="@string/colorBarDefault" > 
    </TextView> 

    <CheckBox 
     android:id="@+id/checkBox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:checked="false" 
     android:clickable="false" 
     android:focusable="false" 
     android:focusableInTouchMode="false" 
     android:paddingLeft="45dp" 
     android:text="@string/checkBoxDefault" > 
    </CheckBox> 

    <TextView 
     android:id="@+id/sqlID" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/sqlIDDefault" 
     android:visibility="gone" > 
    </TextView> 

</LinearLayout> 

LÖSUNG:

EDIT: REINIGUNG Das Projekt half!

Antwort

1

Verwendung view.setTag(objTextview);

TextView colorBar = (TextView)view.getTag(); 
+0

was objTextview ist? – myzinsky

+0

Objekt von (?) Art, dh. Textansicht, Schaltfläche, beliebiges Steuerelement oder Zeichenfolge, Int, Array usw. –

+0

wo soll ich setzen "verwenden Sie view.setTag (objTextview);" genau in meinem Code? – myzinsky

Verwandte Themen