Forum Visual Studio

Android Scroll view 'scrollchange' event when attached to delegate throws runtime Error !

My team is working on Xamarin Android Development. In a view I have a scrollView and i am using 'ScrollChange' event of scrollview to detect scroll movement and performing required actions. It works fine for my machine. But when i used the same code on another machine, i am getting run-time error as follows:

Unhandled Exception:


  • DeepakBadoniDeepakBadoni USMember

    After spending couple of hours, i make few changes to my code and now its working fine. Earlier I was using following code to attach the delegate.

        ScrollView ScrollView1 = (ScrollView)FindViewById(Resource.Id.ScrollView1);
                    ScrollView1.ScrollChange += ScrollView1_ScrollChange;
         private void OnScrolled(object sender, EventArgs e)
                    ScrollView scrollView = sender as ScrollView;
                    double scrollingSpace = scrollView.GetChildAt(0).Height - scrollView.Height;
                    if (scrollingSpace <= scrollView.ScrollY) // Touched bottom
                        // Do the things you want to do
                        Toast.MakeText(this, "You have reached to the bottom!", ToastLength.Short).Show();

    Now the above code was working on almost every machine but not on all the machine. Few machines throwing the error as mentioned above.
    Then i altered the delegate method params as follows:

    void ScrollView1_ScrollChange(object sender, View.ScrollChangeEventArgs e)

    Now rest definition remains the same. Now this delegate works fine for every machine.

Sign In or Register to comment.