How to retrieve data from cursor class

后端 未结 3 469
借酒劲吻你
借酒劲吻你 2020-11-28 10:12

I need to know how to retrieve data from cursor. I need this because the ringtonemanager returns all the audio files in form of cursor object, I need to know how to retrieve

相关标签:
3条回答
  • 2020-11-28 10:57

    This looks a bit better:

    for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
        ...
    }
    
    0 讨论(0)
  • 2020-11-28 11:02

    Salvador's answer will continue to fetch data from the row after the last row because moveToNext() will only return false when the cursor is pointing at the row after the last row. It will continue to iterate even if the cursor is pointing at the last row.

    The correct template should be:

    if (cursor.moveToFirst()){
       while(!cursor.isAfterLast()){
          String data = cursor.getString(cursor.getColumnIndex("data"));
          // do what ever you want here
          cursor.moveToNext();
       }
    }
    cursor.close();
    
    0 讨论(0)
  • 2020-11-28 11:04

    Once you have the Cursor object, you can do something like this:

    if (cursor.moveToFirst()){
       do{
          String data = cursor.getString(cursor.getColumnIndex("data"));
          // do what ever you want here
       }while(cursor.moveToNext());
    }
    cursor.close();
    
    0 讨论(0)
提交回复
热议问题