M0286_Libro Curso
2: Avanzado en Android
String[] selectionArgs, String orderBy) { long id = Long. parseLong (uri. selection = appendRowId(selection, id); } // traemos la BBDD y ejecutamos la consulta SQLiteDatabase db = access.getReadableDatabase(); Cursor cursor = db.query( TABLE_NAME , projection, selection, selectionArgs, null, null, orderBy); // Le decimos al cursor cual el la URI a buscar, // que detecta cuando cambia la fuente de sus datos cursor.setNotificationUri(getContext(). if (uriMatcher.match(uri) == ACCESS_ID ) {
getPathSegments().get(1));
getContentResolver(), uri); return cursor; } @Override
public String getType(Uri uri) {
switch (uriMatcher.match(uri)) { case ACCESS : return CONTENT_TYPE ; case ACCESS_ID : return CONTENT_ITEM_TYPE ; default:
throw new IllegalArgumentException(“URI
desconocida “ + uri); } } @Override
public Uri insert(Uri uri, ContentValues values) { SQLiteDatabase db = access.getWritableDatabase(); // Validamos la URI requerida if (uriMatcher.match(uri) != ACCESS ) { throw new IllegalArgumentException(“URI // Insertamos en la BBDD long id = db.insertOrThrow( TABLE_NAME , null, values); // Notificamos cualquier cambio Uri newUri = ContentUris. withAppendedId ( CONTENT_URI , id); getContext().getContentResolver().
desconocida “ + uri); }
notifyChange(newUri, null);
139
Made with FlippingBook - Online catalogs