Cursor.moveToNext()返回false,而Cursor.getCount()表示超过1行

时间:2013-12-01 15:40:08

标签: android sqlite

我在我的Sqlite DB中运行查询..

我将结果保存在我的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 Debug:

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,但这一举动是假的......

1 个答案:

答案 0 :(得分:1)

您正在将此Cursor传递给此调用中的另一个方法:

PicoEvent event = PicoEventCreator.createPicoEvent(cursor);

我敢打赌,该方法会在光标返回之前将光标推进到最后。