Exemple utilisation CursorLoader
Bonjour,
je débute avec l'utilisation de SQLite et j'essaye d'utiliser un cursor loader pour l'exploitation de ma BDD.
Pour une table nommée "TableLifetouchRespirationRate" j'aimerai récupérer tout les id des lignes ou la colonne est égale a faux.
Traduction SQL:
Code:
" SELECT id FROM TableLifetouchRespirationRate WHERE acknolegment_message = false "
J'ai tente un truc comme ça:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| String[] projection = {
TableLifetouchRespirationRate.COLUMN_ID,
TableLifetouchRespirationRate.COLUMN_LIFETOUCH_ID,
TableLifetouchRespirationRate.COLUMN_RESPIRATION_RATE,
TableLifetouchRespirationRate.COLUMN_SESSION_NUMBER,
TableLifetouchRespirationRate.COLUMN_TIMESTAMP,
TableLifetouchRespirationRate.COLUMN_ACKNOWLEDGMENT_MESSAGE
};
Context context = this;
Uri uri = IsansysPatientGatewayContentProvider.CONTENT_URI_RESPIRATION_RATES;
String selection = TableLifetouchRespirationRate.COLUMN_ACKNOWLEDGMENT_MESSAGE;
String where = "Where = false";
String[] selectionArgs = {where};
String sortOrder = "ORDER BY _id";
cursorLoader = new CursorLoader(context, uri, projection, selection, selectionArgs, sortOrder); |
Si besoin je peux vous fournir le code complet et le content provider.
Je n'ai pas trouve d'exemple concret pour l'utilisation de ce loader, je ne comprends pas vraiment le paramètre "selectionArgs".
Merci de votre aide
Solution exemple CursorLoader
J'ai trouve la solution:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
Context context = this;
// URI table
Uri uri = IsansysPatientGatewayContentProvider.CONTENT_URI_RESPIRATION_RATES;
// URI columns to get from table class // Uri des colonnes a obtenir
String[] projection = {
TableLifetouchRespirationRate.COLUMN_ID,
TableLifetouchRespirationRate.COLUMN_LIFETOUCH_ID,
TableLifetouchRespirationRate.COLUMN_RESPIRATION_RATE,
TableLifetouchRespirationRate.COLUMN_ACKNOWLEDGMENT_MESSAGE,
TableLifetouchRespirationRate.COLUMN_TIMESTAMP,
TableLifetouchRespirationRate.COLUMN_SESSION_NUMBER
};
// Dans la colonne ACKNOWLEDGMENT_MESSAGE...
String selection = TableLifetouchRespirationRate.COLUMN_ACKNOWLEDGMENT_MESSAGE + "=?"; // null; //
// selectionner les lignes dont la valeur est "0" (il est possible d'ajouter des arguments sur diferentes colonnes)
String[] selectionArgs = {"0"}; // null; //
String sortOrder = null;
cursorLoader = new CursorLoader(context, uri, projection, selection, selectionArgs, sortOrder); |
Bon codage :mouarf: