update()
を使用してオブザーバーにContentProvider
通知を実装しましたgetContext().getContentResolver().notifyChange(uri, null);
私の明らかな必要性は、1つの行だけが影響を受けるときはいつでも、行固有のURIで通知したいのですが、そうする方法を見つけることができなかったということです。のような追加のクエリ"select id where selectionArgs"
でこれを行うことができますが、これは愚かな方法になります。
onchange(boolean, uri)
ContentProvider.update()
特定の行の代わりに完全なuriを取得します。これは、同じ行を送信しているためであることが理解しやすいです。
some code for more clarity
MyContentProviderのupdate()メソッド
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
Log.d("TAG", "update " + uri.getPath());
int count = 0;
switch (uriMatcher.match(uri)) {
case BOOKS:
count = booksDB.update(DATABASE_TABLE, values, selection, selectionArgs);
break;
case BOOK_ID:
count = booksDB.update(DATABASE_TABLE, values,
_ID + " = " + uri.getPathSegments().get(1)
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""),
selectionArgs);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (count == 1) {
Cursor c = query(uri, new String[] { _ID }, selection, selectionArgs, null);
long rowId = Long.valueOf(c.getString(c.getColumnIndex(_ID)));
uri = ContentUris.withAppendedId(CONTENT_URI, rowId);
}
getContext().getContentResolver().notifyChange(uri, null);
return count;
}
テーブルを更新します
getContentResolver().update(MyContentProvider.CONTENT_URI, values1, MyContentProvider._ID+"<?", new String[]{"3"}));
率直に言って、コードは質問とほとんど関係がなく、コンテキストを提供しようとしているだけです