0
投錯誤我獲得以下錯誤(線19是// XXX中的代碼):ViewBinder與Android 4.0
十月4日至10日:35:08.301:E/AndroidRuntime(12417): 的java。 lang.ClassCastException:android.widget。 TextView的不能被轉換到 android.widget.CheckBox 10月4日至10日:35:08.301: E/AndroidRuntime(12417):在 ms.jung.andorid.caldavtodo.CalDavToDoViewBinder.setViewValue(CalDavToDoViewBinder.java:19)
我的代碼:
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;
}
}
我很困惑,因爲R.id.checkBox
絕對是一個CheckBox
。
編輯:
<?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>
SOLUTION:
編輯:清潔幫助的項目!
是什麼objTextview? – myzinsky 2012-04-10 08:47:08
(?)類的對象,即。 Textview,Button,任何控件或字符串,int,數組等... – 2012-04-10 08:49:31
我應該在哪裏放置「use view.setTag(objTextview);」完全在我的代碼? – myzinsky 2012-04-10 08:51:38