In Xamarin Android how can we extend the ScrollView in order to use the protected OnScrollChanged event?
Specifically, How do we extend the ScrollView to allow an EventHandler to be registered to the OnScrollChanged event? What other methods of ScrollView need to be implemented in a class that extends ScrollView?
Reasons:
The Android ScrollView does not have a way to listen for a scroll event. There have been various questions regarding how to extend ScrollView in native Android Java, however, there is not a question and answer addressing how to apply this to Xamarin.
In order to extend ScrollView in this way we should implement 3 constructors
We also need to override the OnDraw method
To achieve the functionality of an event that we can respond to when the user scrolls we need to override the OnScrollChanged method.
There are multiple ways to allow event listening and handling, but in order to be consistent with Xamarin we can add a public EventHandler property to our class.
We will want to pass along the values from OnScrollChanged to the EventHandler, so let's extend EventArgs
Finally, don't forget to initialize our handler in each of our constructors
Put it all together and it might look something like this
Extended EventArgs class
Extended ScrollView class
This Q&A was helpful in figuring this problem out: Scrollview listener is not working in Xamarin for Android?