I\'m trying to use picasso library to be able to load url to imageView, but I\'m not able to get the context to use the picasso library correctly.
Short answer:
Context context;
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
context = recyclerView.getContext();
}
Explanation why other answers are not great:
Context to the adapter is completely unnecessary, since RecyclerView you can access it from inside the classContext at ViewHolder level means that you do it every time you bind or create a ViewHolder. You duplicate operations.Activity lifespan (which would be weird) then you already have a leak.