Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve data from cursor class

Tags:

android

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 the values.

Anbudan.

like image 649
Rakesh Avatar asked May 11 '10 12:05

Rakesh


People also ask

What is Cursor class how it is used?

A Cursor implementation that exposes results from a query on a SQLiteDatabase . This interface provides random read-write access to the result set returned by a database query.

What does Cursor moveToFirst do?

Calling moveToFirst() does two things: it allows you to test whether the query returned an empty set (by testing the return value) and it moves the cursor to the first result (when the set is not empty).

What is Cursor in sqlite?

A Cursor implementation that exposes results from a query on a SQLiteDatabase . SQLiteCursor is not internally synchronized so code using a SQLiteCursor from multiple threads should perform its own synchronization when using the SQLiteCursor.


2 Answers

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(); 
like image 83
Salvador Avatar answered Sep 29 '22 14:09

Salvador


This looks a bit better:

for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {     ... } 
like image 45
tcb Avatar answered Sep 29 '22 14:09

tcb