2011-05-04 57 views
0

例如,當我向數據庫添加一行時,我運行ff。代碼,如何在數據庫更改時重新引導光標適配器?

  Cursor crs = adapterToRefresh.getCursor(); 
      crs.close(); 
      crs = this.dbImmunization.queryAll(); 
      this.startManagingCursor(crs); 
      crs.moveToFirst(); 
      adapterToRefresh.changeCursor(crs); 
      adapterToRefresh.notifyDataSetChanged(); 

其中crs是遊標在遊標適配器內的檢索。

到目前爲止,這個實現給了我一個CursorIndexOutOfBoundsException的錯誤。

幫助任何人!

+1

請發佈堆棧跟蹤。 – trojanfoe 2011-05-04 09:46:09

回答

0

首先使用sqlite瀏覽器查看正確創建的表和行。第二,當你遍歷數據庫時,你將如何進入最後一行。可能是有問題的。只有當你顯示你的logcat輸出時,它纔會更清晰。

+0

adapterToRefresh.getCursor().requery(); \t \t \t \t adapterToRefresh.notifyDataSetChanged();,我使用這些代碼,但沒有工作。:( – MarkJ 2011-05-04 10:11:42

0

你已經調用了startManagingCursor(遊標),因此你不需要調用adapter.notifyDataSetChanged()。相反,當您需要刷新其查詢並獲取數據時,請調用cursor.requery()。

相關問題