MattBorg
MattBorg

Reputation: 95

problems declaring Database helper object without onCreate() available

I am trying to access a DatabaseHelper class after hitting a button in a recyclerview. The problem is that the Recycler Adapter i have the button in does not extend AppCompatView and i don't get the onCreate() method, so i can't use the below to declare a DatabaseHelper object to access by db functions. I cannot use the 'this' keyword to get the current context.

I ususally do the below. I extend AppCompatActivity to get the onCreate() method:

enter image description here

enter image description here

But i have to extend another class and can't use the 'this' keyword to get the current context and can't figure out how to access my DatabaseHelper class. enter image description here

The button i am trying to click is in a cardview recyclerview: enter image description here

Can anyone help me get the current context in a different way so i can access database??? thanks.

Upvotes: 0

Views: 43

Answers (1)

Shahrukh khan
Shahrukh khan

Reputation: 196

It’s fairly simple. Make a parametrized constructor in GetInfoRecyclerAdapter class and from the main activity pass the context of the activity when creating adapter class object.

That would solve your issue.

Upvotes: 2

Related Questions