Scrolling Before Finding: Refreshing the RecyclerView

Nathan Sokalski 4,121 Reputation points
2021-09-03T19:11:49.157+00:00

I have a RecyclerView that, like many RecyclerView(s), scrolls items offscreen. If I call FindViewHolderForAdapterPosition for an item that is currently offscreen, I receive a NullReferenceException, which is to be expected. When this is the scenario, I want to scroll the item back into view (which I do using SmoothScrollToPosition), and then call FindViewHolderForAdapterPosition. However, FindViewHolderForAdapterPosition still returns a NullReferenceException until the next round of events (the user presses the button again). How can a make the RecyclerView recognize that the item is now visible (or onscreen or whatever you want to call it)? Is there some kind of refresh method I need to call? The Notify methods are obviously not appropriate because this is not a data updating scenario. Any ideas?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,312 questions
{count} votes