我正在我的 Sqlite 数据库中运行查询..
我将结果保存在我的 Cursor 中,我正在遍历它以获得所有结果..
allotugh 我正在检查并看到游标有超过 1 行,它只给我第一行,因为 moveToNext() 总是返回 false..
这是我的迭代代码:
Cursor cursor = getEventsDetails(db, selection, null);
Log.e("cursor before", "count" + cursor.getCount());
boolean moveToNext = cursor.moveToFirst();
if (moveToNext)
{
do
{
//Create a new PicoEvent instance with the event's details
PicoEvent event = PicoEventCreator.createPicoEvent(cursor);
Log.e(event.getName(), event.getStartTime().toLocaleString());
Log.e("cursor in", "count" + cursor.getCount());
moveToNext = cursor.moveToNext();
Log.e("moveToNext", "move: " + moveToNext);
if (!isEventExists(eventsList, event))
eventsList.add(event);
} while (moveToNext);
}
这是 Logcat 调试:
12-01 17:33:07.774: E/cursor before(5950): count4
12-01 17:33:08.094: E/Pico Demo Event(5950): 1 בדצמ 2013 11:00:00
12-01 17:33:08.124: E/cursor in(5950): count4
12-01 17:33:08.124: E/moveToNext(5950): move: false
如您所见,行数是 4,但移动是错误的...
最佳答案
您正在将此 Cursor
传递给此调用中的另一个方法:
PicoEvent event = PicoEventCreator.createPicoEvent(cursor);
我敢打赌,该方法会在光标返回之前将光标推进到末尾。
关于android - Cursor.moveToNext() 返回 false 而 Cursor.getCount() 表示超过 1 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20313896/