I have a use case where I need a reference to the parent RecyclerView
from inside the adapter, specifically inside the onBindViewHolder
method. So far what I am doing is assigning it to a private class member in the onCreateViewHolder
method passing along the viewGroup parent
arg like so:
private ViewGroup mParent;
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// inflater logic.
mParent = parent;
}
And referencing the parent RecyclerView
in onBindViewHolder
like this:
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
// binder logic.
((RecyclerView)mParent).blahBlahBlah();
}
Is there a better way of doing this? Maybe RecyclerView.Adapter
has a way that I may have missed?