i have a problem with a cursor. i created a alarm manager that pick a value to compare with another in looping.
My problem is this: if the cursor is outside of the loop this pick only my first value (if exsist only one value pick only this obviously)…. if the cursor is in the loop, this pick only last value (if exsist only one value pick only this obviously).
how to fix this?
my query:
public Cursor getRegistry2()
{
return (getReadableDatabase().query(
TabRegistry.TABLE_NAME,
TabRegistry.COLUMNS,
TabRegistry._ID,
null,
null,
null,
null));
my cursor in service:
Cursor c5 = databaseHelper.getRegistry2();
c5.moveToFirst();
while(c5.isAfterLast() == false){
tipe = c5.getString(c5.getColumnIndex(TabRegistry.TYPE));
status = c5.getString(c5.getColumnIndex(TabRegistry.STATUS));
number = c5.getString(c5.getColumnIndex(TabRegistry.NUMBER));
c5.moveToNext();
}
c5.close();
thanks in advance!
As I mentioned in my comment, if you are actually trying to find a particular item you need to actually look for it.
Assuming you are looking to compare the status, you might do this:
This would break out of your loop, leaving your values set for the item you were looking for.
Personally, that’s a lot of computing overhead and I’d just make the query to look for the comparison value directly and then check and see if the returned cursor was empty. Much simpler.