Android 通过数据库记录循环代码
我有一个数据库,里面有一些记录,我有我希望在每一行上执行的代码,但是我在创建一个合适的循环时遇到了困难,我一直在尝试(movetonext),但它一直不起作用Android 通过数据库记录循环代码,android,sqlite,Android,Sqlite,我有一个数据库,里面有一些记录,我有我希望在每一行上执行的代码,但是我在创建一个合适的循环时遇到了困难,我一直在尝试(movetonext),但它一直不起作用 cursor = getAppts(); cursor.moveToNext(); String titlefromdb = cursor.getString(3); if (strTitle.equals(titlefromdb) && cursor.getString(1).equals(dateselforap
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来保存当前行的title字段和if语句,然后移动到下一行。您可以尝试
cursor.moveToFirst();
loop with some sort of check
cursor.moveToNext();
end loop
。。。我也会尝试对你的“它不起作用”的说法进行限定。什么不起作用?请格式化您的代码。我从自己的数据库中收到一个边界外异常。