简体   繁体   English

android游标在无限循环中

[英]android cursor in infinite loop

I have cursor that comes from a cursor loader. 我有来自游标加载器的游标。 The problem is if I try to move through that cursor it will not move foward and puts in a endless loop. 问题是,如果我尝试移动光标,它将不会向前移动并进入无限循环。

  public void onLoadFinished(Loader<Cursor> loader, final Cursor cursor) {
    Log.d(TAG, "CALLED onLoadFinished");
    ...
    else if(loader.getId() == LOADER_1)
    {
        while(cursor.moveToFirst())
        {
              Log.d(TAG, "LOOPING");
              cursor.moveToNext();
        }
    }
 }

Your current while loop will not work. 您当前的while循环不起作用。 Right now you're moving the cursor to the first position in the while condition then inside the while block you're pushing the cursor to the next position. 现在你将光标移动到while条件中的第一个位置,然后在while块内,你将光标移动到下一个位置。 As the while block is finished the condition will be tested again so cursor.moveToFirst() will be called again. while块完成时,将再次测试条件,因此将再次调用cursor.moveToFirst() This will continue again and again. 这将一次又一次地继续。 Basically you'll move from the first position to the second position of the cursor in an infinite loop. 基本上你将在无限循环中从光标的第一个位置移动到第二个位置。

The loop should be like this: 循环应该是这样的:

while(cursor.moveToNext()) {
     Log.d(TAG, "LOOPING");
     // do other stuff 
     // each time you'll have a new row from the cursor
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM