我在我的數據庫類中使用了rawQuery
並將光標返回到我的適配器,該適配器是CursorAdapter
,我將其與自定義的ListView
項一起使用。如何在使用rawQuery和CursorAdapter時關閉我的光標
該視圖在屏幕上繪製或如何管理這個光標後,該遊標是否自動關閉?這種情況下的最佳做法是什麼?
如果我在DB類中關閉了這個遊標,我無法從我的適配器訪問它們。
感謝您的時間和精力幫助我。
編輯添加一些代碼段用於更好地理解
這是我的活動代碼:
calAdapter = new CalendarListAdapter(context, dbHelper.getAllCalendars());
drawerList.setAdapter(calAdapter);
這是我的光標
public Cursor getAllCalendars() {
String query = "SELECT calendarId as _id, calendarName, calState, calShow FROM "
+ TABLE_CALENDAR_LIST;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(query, null);
return cursor;
}
你可以發佈你的代碼 – KOTIOS