Created
May 30, 2016 09:42
-
-
Save GlennReilly/4b825f83fb8e8d0ca8615149f66046c2 to your computer and use it in GitHub Desktop.
How to read an SQLite DB in android with a cursorloader?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Android Guide suggests to create a ContentProvider when you want to share you data with other applications. If you don't need this, you can just override method loadInBackgroud() of the CursorLoader class. For example write in you onCreateLoader: | |
return new CursorLoader( YourContext, null, YourProjection, YourSelection, YourSelectionArgs, YourOrder ) | |
{ | |
@Override | |
public Cursor loadInBackground() | |
{ | |
// You better know how to get your database. | |
SQLiteDatabase DB = getReadableDatabase(); | |
// You can use any query that returns a cursor. | |
return DB.query( YourTableName, getProjection(), getSelection(), getSelectionArgs(), null, null, getSortOrder(), null ); | |
} | |
}; | |
//from http://stackoverflow.com/questions/18326954/how-to-read-an-sqlite-db-in-android-with-a-cursorloader |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment