SimpleCursorTreeAdapter - “只应在光标有效时调用”

时间:2014-01-23 14:08:55

标签: android

我有一个从SimpleCursorTreeAdapter扩展的适配器,并附加到ExpandableListActivity。 每次设备更改方向时,SimpleCursorTreeAdapter都会抛出异常! (仅当至少扩展了1个项目时) “java.lang.IllegalStateException:只应在游标有效时调用它” 我的OnCreate

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.disciplines);
        dbHelper.open();
        dataCursor = dbHelper.getDisciplinesOneField();
        DisciplineAdapter adapter = new DisciplineAdapter(this, dataCursor,
                R.layout.discipline_row
                , new String[]{Discipline.NAME}
                , new int[]{R.id.discipline_row_name}
                , R.layout.lesson_child, new String[]{}, new int[]{});
        setListAdapter(adapter);
        registerForContextMenu(getExpandableListView());
    }

我的适配器:

private class DisciplineAdapter extends SimpleCursorTreeAdapter{
        public DisciplineAdapter(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 void bindChildView(View view, Context context, Cursor cursor,
                boolean isLastChild) {
            super.bindChildView(view, context, cursor, isLastChild);
                    // Filling my views here
        }


        @Override
        protected Cursor getChildrenCursor(Cursor groupCursor) {
            long disciplineId = groupCursor.getInt(groupCursor.getColumnIndex("_id"));
            return dbHelper.getLessonsForDiscipline(disciplineId);
        }

    }

我做错了什么?缺什么? 谢谢。

0 个答案:

没有答案