Reputation: 95
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:
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.
The button i am trying to click is in a cardview recyclerview:
Can anyone help me get the current context in a different way so i can access database??? thanks.
Upvotes: 0
Views: 43
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