Get a context in a recycler view adapter

Copied from Stackoverflow: How to get a context in a recycler view adapter

  1. Pass Context as an argument to YourAdapter and keep it as class field.
  2. 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.
  3. 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.)