So, I have a query returning a Cursor with all values (I confirmed this with cursor.getCount() where the int returned was equivalent to the number of records in the database), but for some reason, no matter what iteration-loop I write I can never seem to retrieve the first value of the list.
private void addAllUnsentCrapportsToList() {
mDbAdapter.open();
Cursor cursor = mDbAdapter.getAllCrapports();
cursor.moveToFirst();
String text = "";
while(cursor.isAfterLast() == false){
text = text
+ "typ: " + cursor.getString(cursor.getColumnIndex(DbAdapter.CRAPPORT_KEY_GARBAGETYPE))
+ " kommentar: " + cursor.getString(cursor.getColumnIndex(DbAdapter.CRAPPORT_KEY_COMMENT))
+ "\n";
cursor.moveToNext();
}
unsentCrapportList.setText(text);
}
This bit of code displays all the values, excluding the first. What am I doing wrong? I've tried numerous approaches, including do while, while etc, but have always ended up with the same fault.
What am I missing?
I dont see anything wrong with your code. So maybe you are not getting the first value from the db? Have you tried to print the data just after cursor.moveToFirst(); to see which is the first element?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With