简体   繁体   中英

Retrieve data from a Cursor

I have a database with only one table : notifications (which contains an id, a title, a note, etc) I'm trying to have an Activity that displays the title of the notifications through a ListActivity. And when the user clicks on one of the title, it displays the whole notification.

I have a Cursor that retrieves data from the database :

public Cursor getAllNotifications() {
return db.query(DATABASE_TABLE, new String[] { KEY_ROWID,
        KEY_DAYOFWEEK, KEY_HOUR_BEG, KEY_HOUR_END, KEY_ROOM,
        KEY_TEACHER, KEY_NOTE}, null, null, null,
        null, null);
}

In the class that extends ListActivity, I have a private String[] notificationsList;

but I don't know how to retrieve the data because the getAllNotifications() method returns a Cursor.

Use

cursor.getString(/**columnindex**/);

And similar functions : Refer http://developer.android.com/reference/android/database/Cursor.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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