我正在尝试添加用户选中的所有checkbox中的所有值。此外,所有未选中的复选框都将被跳过。但是,我会在每个值之后跳过一个。我需要帮助。
if(cursor.moveToFirst())
{
do
{
if (cursor.getInt(10)>0 == false)
{
cursor.moveToNext();
n += cursor.getDouble(9);
}
else n += cursor.getDouble(9);
} while(cursor.moveToNext());
}
你做moveToNext()的太多了
尝试删除循环中的一个:
if(cursor.moveToFirst())
{
do
{
if (cursor.getInt(10)>0 == false)
{
n += cursor.getDouble(9);
}
else n += cursor.getDouble(9);
} while(cursor.moveToNext());
}
每次调用cursor.moveToNext()
时,它都会转到下一行-每个循环调用两次(在while
子句和do
中)
只需在do
中删除对moveToNext()
的调用,您就应该设置好了:
if(cursor.moveToFirst()) // <-- this will advance the cursor to the first row
{
do
{
if (cursor.getInt(10)>0 == false)
{
//cursor.moveToNext(); <--you already called this!
n += cursor.getDouble(9);
}
else n += cursor.getDouble(9);
} while(cursor.moveToNext()); // <-- this advances the cursor
}