2012-03-20 18 views
0

我有一個數據庫中的一些記錄,我有我希望在每一行執行的代碼,但我無法創建一個合適的循環,我試圖while(movetonext),但它沒有加工。通過數據庫記錄循環代碼

cursor = getAppts(); 

cursor.moveToNext(); 

String titlefromdb = cursor.getString(3); 

if (strTitle.equals(titlefromdb) && cursor.getString(1).equals(dateselforap)) 
{ 
    // matching code update box 

    final Dialog matchdiag = new Dialog(CW2Organisor.this); 
    matchdiag.setContentView(R.layout.apptmatch); 
    matchdiag.setTitle("View/Edit Appointment"); 
    matchdiag.setCancelable(true); 

    TextView matchtxt = (TextView) matchdiag.findViewById(R.id.matchtxt); 

    matchtxt.setText("Appointment \"" + titlefromdb + "\" already exists, please choose a different event title"); 

    Button btnmatchok = (Button) matchdiag.findViewById(R.id.btnmatch); 
    btnmatchok.setOnClickListener(new OnClickListener() { 

     // on click for cancel button 

     @Override 
     public void onClick(View v) { 
      matchdiag.dismiss(); 
     } 
    }); 

    matchdiag.show(); 
} 
else 
{ 
addAppt(strTime, strTitle, strDet); 
dialog.dismiss(); 
} 

我需要爲我的數據庫中的每一行,我會需要titlefromdb保存當前行的標題字段和用於if語句來運行,然後移動到下一行。

+0

請格式化您的代碼。 – 2012-03-20 19:36:20

回答

0

你可以嘗試

cursor.moveToFirst(); 

loop with some sort of check 
    cursor.moveToNext(); 
end loop 

...我也想嘗試限定您「它不工作」的聲明。什麼不工作?

+0

我從我的數據庫中獲得了一個outofbounds異常,我相信。 – nexus490 2012-03-20 20:05:53