我理解爲什麼我的ListActivity和其相應的的ListView空當我打電話的close()方法上光標對象有問題嗎?ListView的空當SimpleCursorAdapter關閉()
讓我解釋一下我自己有點...
我retreive從DB一些價值觀和得到的結果在我的光標對象。之後,我創建了我的SimpleCursorAdapter,並將數據庫中的列與我的listView中的字段綁定。
得好好的,但是......
如果我打電話cursor.close()在的onCreate()方法我的ListView的末尾顯示是空的?
如果我登錄從光標到logcat的他們在那裏的值,直到調用cursor.close()和非常有意義,但爲什麼當cursor.close()被稱爲listAdapter清空? ? 我希望ListAdapter listAdapter =新SimpleCursorAdapter(...)持有被「綁定」到的ListView直到我們activity被銷燬值...
爲什麼會這樣呢?何時以及爲什麼需要關閉光標?
public class ListTrainingsView extends ListActivity{
private SQLiteDatabase db;
private ListAdapter listAdapter;
private Cursor cursor;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_trainings);
DatabaseHelper helper = new DatabaseHelper(this);
this.db = helper.getWritableDatabase();
this.cursor = db.query("trainings", fields, null, null, null, null, null);
startManagingCursor(cursor);
this.listAdapter = new SimpleCursorAdapter(this,
R.layout.list_trainings_item,
cursor,
new String[] {"name"},
new int[] { R.id.name_entry}
);
this.setListAdapter(this.listAdapter);
//If I call
//cursor.close();
//shown list is empty
另一個問題是更基本的Java語言類型的問題......我來自PHP的面向對象的背景和那裏,如果你定義的成員變量必須使用語法$這個 - 對象方法與它合作>光標。我注意到,在Android/Java中,我不必使用this.cursor.getCount()以從中獲取參考/值。這足以說明cursor.getCount()這是怎麼來的?