Get a context in a recycler view adapter
Copied from Stackoverflow: How to get a context in a recycler view adapter
- Pass Context as an argument to
YourAdapter
and keep it as class field. - Use dependency injection to inject Context when you need it. I strongly suggest reading about it. There is a great tool for that -- Dagger by Square.
- Get it from
View
object. In your case this might work for you:view.getContext()
. (I prefer the third option, getting the context from the view. It is the simplest and most straightforward solution.)