Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BikeHistProvider extends ContentProvider {
- // Contract
- public final class Contract {
- public static final String KEY_ID = "_id";
- public static final String KEY_NAME = "name";
- /** Calculated at run time */
- public static final String KEY_MY_TRANSIENT_FIELD = "myTransientField";
- }
- @Override
- public Cursor query(Uri uri, String[] projection,
- String selection, String[] selectionArgs,
- String sortOrder) {
- // Create a Cursor with the field structure defined in
- // Contract
- MatrixCursor mc = new MatrixCursor(new String[]{
- Contract.KEY_ID,
- Contract.KEY_NAME
- Contract.KEY_MY_TRANSIENT_FIELD
- });
- // Apply the query to the underlying database.
- Cursor c = qb.query(db, projection, selection, selectionArgs,
- null, null, orderBy);
- //Move result to MatrixCursor and add transient fields
- c.moveToFirst();
- do {
- //Create new entries
- Object[] values = {
- c.getInt(0), //The key for the database entry
- c.getString(Contract.KEY_NAME),
- calculateTransientField()};
- mc.addRow(values);
- } while (c.moveToNext());
- c.close();
- return mc;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement