2

I have a button in a listview that needs to update the db on clicking. So I have to place the OnClickListener in the bindView method of the CursorAdapter class. So, I cannot invoke

int rowsAffected = getContentResolver().update(mCurrentPetUri, values, null, null);

Since its a static context, I cannot use Context.getContentResolver() also.

Is there a workaround ?

konstantin_doncov
  • 2,725
  • 4
  • 40
  • 100
sjso
  • 277
  • 2
  • 11
  • i cannot refer a non static method from a static context – sjso Jun 28 '17 at 19:35
  • 1
    Pass a `Context`, such as the `Activity`, into the `ListAdapter`, such as via its constructor. Hold onto it in a field. Call `getContentResolver()` on that `Context`. – CommonsWare Jun 28 '17 at 19:46
  • thanks............... – sjso Jun 28 '17 at 20:03
  • Possible duplicate of [how use getContentResolver in a class without activity?](https://stackoverflow.com/questions/15077955/how-use-getcontentresolver-in-a-class-without-activity) – Logic Sep 30 '17 at 17:26

0 Answers0