RecyclerView ViewHolder Parent is null

Nathan Sokalski 4,111 Reputation points
2022-03-08T20:13:01.123+00:00

I have a RecyclerView Adapter for which I need to access the RecyclerView in OnBindViewHolder. Here is the code from OnCreateViewHolder:

public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{ return new NetWinsValuesViewHolder(LayoutInflater.From(parent.Context).Inflate(Resource.Layout.NetWinsValuesLayout, parent, false)); }

In OnBindViewHolder I have the following:

NetWinsValuesViewHolder vh = holder as NetWinsValuesViewHolder;
RecyclerView rvavgnetwins = vh.llRoot.Parent as RecyclerView;

However, vh.llRoot.Parent ends up being null. I have used this technique to access the RecyclerView plenty of times in the past, so why is it returning null here?

Developer technologies .NET Xamarin
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.