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 theContentProvidersuch that a call togetContentResolver().update(customUri, ...)passing thisUritells my ContentProvider’s overriddenupdate()method to increment the view count for this item, thus avoiding the need to pass values toupdate()via it’sContentValuesparameter.