I'm updating an item in a ListView via the getContentResolver().update()
method, and I'd like to increment a 'views' field via a ContentValue, but can't figure out if this is possible.
I could do this with raw SQL SET views = views + 1
, but setting a ContentValue, such as cv.put("views", "views + 1")
results in the views field being set explicitly to "views + 1" rather than a number.
Any pointers on this on, or am I left to a more manual approach?
Thanks,
Paul
UPDATE:
I've gone back to using raw SQL to perform the update for now, and then manually notify the underlying CursorAdapter of the change via getContentResolver().notifyChange()
. Would still be great if I could figure out a way to do this directly via getContentResolver().update()
, so if anyone has a way to do that, please post it here.
My final solution to this was to use a custom Uri
(along the lines of ...item/5/updateviews
) via the ContentProvider
such that a call to getContentResolver().update(customUri, ...)
passing this Uri
tells my ContentProvider's overridden update()
method to increment the view count for this item, thus avoiding the need to pass values to update()
via it's ContentValues
parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With