Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. public class BikeHistProvider extends ContentProvider {
  2.  
  3. // Contract
  4. public final class Contract {
  5. public static final String KEY_ID = "_id";
  6. public static final String KEY_NAME = "name";
  7. /** Calculated at run time */
  8. public static final String KEY_MY_TRANSIENT_FIELD = "myTransientField";
  9. }
  10.  
  11. @Override
  12. public Cursor query(Uri uri, String[] projection,
  13. String selection, String[] selectionArgs,
  14. String sortOrder) {
  15.  
  16. // Create a Cursor with the field structure defined in
  17. // Contract
  18. MatrixCursor mc = new MatrixCursor(new String[]{
  19. Contract.KEY_ID,
  20. Contract.KEY_NAME
  21. Contract.KEY_MY_TRANSIENT_FIELD
  22. });
  23.  
  24. // Apply the query to the underlying database.
  25. Cursor c = qb.query(db, projection, selection, selectionArgs,
  26. null, null, orderBy);
  27.  
  28. //Move result to MatrixCursor and add transient fields
  29. c.moveToFirst();
  30. do {
  31. //Create new entries
  32. Object[] values = {
  33. c.getInt(0), //The key for the database entry
  34. c.getString(Contract.KEY_NAME),
  35. calculateTransientField()};
  36.  
  37. mc.addRow(values);
  38. } while (c.moveToNext());
  39. c.close();
  40.  
  41. return mc;
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement