通过数据库记录循环代码

时间:2012-03-20 19:33:50

标签: android sqlite

我有一个包含一些记录的数据库,我有我希望在每一行执行的代码,但是我在创建一个合适的循环时遇到了麻烦,我一直在尝试(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语句,然后移动到下一行。

1 个答案:

答案 0 :(得分:0)

你可以尝试

 cursor.moveToFirst();

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

...而且我也会尝试限定你的“它不起作用”的声明。什么不起作用?

相关问题