2012-04-10 4 views
0

에 오류 캐스팅 (라인 19 // XXX 코드에) :ViewBinder 내가 오류 다음 얻을 안드로이드 4.0

04-10 10 : 35 : 08.301 : E/AndroidRuntime (12417) : 자바. lang.ClassCastException : android.widget. ms.jung.andorid.caldavtodo.CalDavToDoViewBinder.setViewValue에서 (CalDavToDoViewBinder.java:19) : 35 : 08.301 : E/AndroidRuntime (12417) 텍스트 뷰는 android.widget.CheckBox 04-10 10 를 캐스팅 할 수 없습니다

내 코드 : R.id.checkBox 확실히 CheckBox 때문에

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; 
    } 
} 

나는 매우 혼란 스러워요.

편집 :

<?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> 

해결책 :

편집 : 프로젝트 도움을 청소!

답변

1

사용

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

objTextview 무엇 view.setTag(objTextview);? – myzinsky

+0

(?) 종류의 객체, 즉. Textview, Button, 모든 컨트롤 또는 문자열, int, 배열 등 ... –

+0

어디에 사용해야 "view.setTag (objTextview);" 정확히 내 코드에? – myzinsky

관련 문제