4
我想要做的是將ListView
放入我的應用程序中,該應用程序使用內部SQLite數據庫來獲取數據。當用戶點擊新數據時,通過執行新的查詢從數據庫中獲取數據。getCheckedItemCount()在光標更改後返回錯誤的值
我已經實現了ListView
項目的自定義視圖,該項目擴展了LinearLayout
並實現了Checkable
接口。作品。
得到了基於CursorAdapter
的自定義適配器。在OnCreate()
中,我使用空白光標將我的適配器設置爲ListView
。
ListView markersList = (ListView) findViewById(R.id.markersList);
Cursor c = null;
MarkersListAdapter adapter = new MarkersListAdapter(this, c, 0);
markersList.setAdapter(adapter);
接下來在AsyncTask
我在doInBackground()
其中通過新的光標onPostExecute()
更新ListView
查詢數據庫。我有這樣做:
adapter.changeCursor(newCursor);
然後我在默認情況下檢查所有項目(用戶只需取消不需要的項目)
for(int i = 0; i < this.markersList.getCount(); i++)
{
this.markersList.setItemChecked(i, true);
}
到目前爲止好。但是當我做
int s = this.markersList.getCheckedItemCount();
我得到錯誤的價值。我想它與舊遊標有關。只有當新光標中的行數小於新光標中的行數時纔會發生這種情況。
一般情況下,我得到這樣的事情
int s = this.markersList.getCheckedItemCount(); // s = 7
int d = this.markersList.getCount(); // d = 5
是否有一個解決的辦法?
謝謝,現在聽起來很明顯。 – ejar