Wednesday, 18 September 2013

Looping over cursor not same count as cursor count on android

Looping over cursor not same count as cursor count on android

In my app I´m using a SimpleCursorAdapter to display contacts.
Each view has it´s own checkbox. in order to check all, I´m going through
the cursor, putting each ID to a Set, which is progressed by the getView()
method to trigger checkboxes.
The problem is here:
int counter = 0;
if (cursor.moveToFirst())
while (cursor.moveToNext()) {
contact_ids_to_skip.add(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)));
counter++;
}
The first list entry is always triggered, because counter is 157, and
cursor.getCount() is 158.
I do not know what is happening here. I thought cursor.moveToFirst() is
putting the cursor into its right position, but thats not the case.
How can I solve this?

No comments:

Post a Comment