Xamarin android开发,滚动视图'scrollchange'事件附加到委托时抛出运行时错误! [英] Xamarin android development, scroll view 'scrollchange' event when attached to delegate throws runtime error !
问题描述
我的团队正在开发Xamarin Android Development。在视图中我有一个scrollView,我正在使用scrollview的'ScrollChange'事件来检测滚动运动并执行所需的操作。它适用于我的机器。但是当我在另一台机器上使用相同的代码时,我得到的运行时错误如下:
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 runtime error as follows:
Unhandled Exception:
Java.Lang.ClassNotFoundException: mono.android.view.View_OnScrollChangeListenerImplementor
我尝试过:
我试图添加额外的类来覆盖,但都是徒劳的。我只是想知道在这台机器上可能会缺少什么导致这样的问题。
What I have tried:
I tried to add additional class to override but all in vain. I am just wondering what can be missing in this machine to cause such issues.
推荐答案
花了几个小时后,我对我的代码进行了一些修改,现在它正在工作精细。之前我使用以下代码来附加委托。
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 ScrollView1_ScrollChange(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.
这篇关于Xamarin android开发,滚动视图'scrollchange'事件附加到委托时抛出运行时错误!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!