下面是来自我的活动的代码以及作为简单光标树适配器子类的内部类。问题是当我单击存在错误的子元素时
protected void onStart() {
super.onStart();
SQLiteDatabase db = new ToDoDatabase(getApplicationContext())
.getWritableDatabase();
Cursor cursor = db.query(true, ToDoDatabase.TABLE_NAME, null, null,
null, null, null, null, null);
CustomCursorTreeAdapter cursorTreeAdapter = new CustomCursorTreeAdapter(
getApplicationContext(), cursor, R.layout.group_item_layout,
new String[] { ToDoDatabase.TASK_NAME_FORMAT_DATE },
new int[] { R.id.groupItem }, R.layout.child_item_layout,
new String[] { ToDoDatabase.TASK_TIME },
new int[] { R.id.childItem });
drawerList.setAdapter(cursorTreeAdapter);
}
public class CustomCursorTreeAdapter extends SimpleCursorTreeAdapter {
public CustomCursorTreeAdapter(Context context, Cursor cursor,
int groupLayout, String[] groupFrom, int[] groupTo,
int childLayout, String[] childFrom, int[] childTo) {
super(context, cursor, groupLayout, groupFrom, groupTo,
childLayout, childFrom, childTo);
}
@Override
protected Cursor getChildrenCursor(Cursor group) {
SQLiteDatabase db = new ToDoDatabase(getApplicationContext())
.getWritableDatabase();
return db
.query(
ToDoDatabase.TABLE_NAME,
new String[] { ToDoDatabase.TASK_TIME },
ToDoDatabase.TASK_NAME_FORMAT_DATE + " = ? ",
new String[] { group.getString(group
.getColumnIndex(ToDoDatabase.TASK_NAME_FORMAT_DATE)) },
null, null, null, null);
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
我的 logcat 的输出如下。此外,我为 expendableList groupitem 获得了相同的价值。例如,如果我有两个“A”,那么我会得到 2 个具有相同子项的“A”。我是一个 android 初学者
10-14 23:52:11.908: E/AndroidRuntime(28080): java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.database.CursorWindow.nativeGetLong(Native Method)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.database.CursorWindow.getLong(CursorWindow.java:515)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:75)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.widget.CursorTreeAdapter$MyCursorHelper.getId(CursorTreeAdapter.java:436)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.widget.CursorTreeAdapter.getChildId(CursorTreeAdapter.java:173)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.widget.ExpandableListConnector.getItemId(ExpandableListConnector.java:427)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.widget.AdapterView.getItemIdAtPosition(AdapterView.java:756)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.widget.AdapterView.setSelectedPositionInt(AdapterView.java:1128)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.widget.AbsListView.onTouchEvent(AbsListView.java:3165)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.View.dispatchTouchEvent(View.java:5604)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2054)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1815)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2060)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1829)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2060)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1829)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2060)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1829)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2060)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1829)
10-14 23:52:11.908: E/AndroidRuntime(28080): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1917)
10-14 23:52:11.908: E/AndroidRuntime(28080): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1376)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:255)
10-14 23:52:11.908: E/AndroidRuntime(28080): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1865)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.View.dispatchPointerEvent(View.java:5784)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2890)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.os.Handler.dispatchMessage(Handler.java:99)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.os.Looper.loop(Looper.java:137)
10-14 23:52:11.908: E/AndroidRuntime(28080): at android.app.ActivityThread.main(ActivityThread.java:4448)
10-14 23:52:11.908: E/AndroidRuntime(28080): at java.lang.reflect.Method.invokeNative(Native Method)
10-14 23:52:11.908: E/AndroidRuntime(28080): at java.lang.reflect.Method.invoke(Method.java:511)
10-14 23:52:11.908: E/AndroidRuntime(28080): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
10-14 23:52:11.908: E/AndroidRuntime(28080): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
10-14 23:52:11.908: E/AndroidRuntime(28080): at dalvik.system.NativeStart.main(Native Method)