Xamarin android' MainActivity'没有实现接口成员

时间:2016-11-17 07:19:59

标签: android visual-studio-2015 xamarin.android scrollview oxyplot

我正在使用Visual Studio中的xamarin android。我在scroll view中添加了layout,在其中我放置了linear layout,然后放了两个plot views,其中有两个图表被初始化。在运行应用程序时,我收到了以下错误

'MainActivity' does not implement interface member 'ViewTreeObserver.IOnScrollChangedListener.OnScrollChanged()'

Bellow是我的布局xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainLayout_ScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minWidth="25px"
    android:minHeight="25px"
    android:id="@+id/linearLayout1">
    <OxyPlot.Xamarin.Android.PlotView
        android:layout_width="match_parent"
        android:layout_height="254.5dp"
        android:id="@+id/plotView1" />
    <OxyPlot.Xamarin.Android.PlotView
        android:layout_width="match_parent"
        android:layout_height="309.5dp"
        android:id="@+id/plotView2" />
</LinearLayout></ScrollView>

Bellow是我的主要活动代码,包括

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using OxyPlot.Xamarin.Android;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using OxyPlot.Annotations;
using Java.Util;
using System.Linq;
using System.Collections.Generic;
[Activity(Label = "SampleChart", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity  , ViewTreeObserver.IOnScrollChangedListener
{

    private static Toast _PageToast;
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);

        PlotView view = FindViewById<PlotView>(Resource.Id.plotView1);
        PlotView view2 = FindViewById<PlotView>(Resource.Id.plotView2);

        view.Model = CreatePlotModel();
        view2.Model = CreatePlotModel2();

        ScrollView MainLayout_ScrollView1 = (ScrollView)FindViewById(Resource.Id.MainLayout_ScrollView1);
        MainLayout_ScrollView1.ViewTreeObserver.AddOnScrollChangedListener(this);
    }

public void OnScrollChange()
    {
        if(_PageToast !=null)
        {
            _PageToast.Cancel();
        }

        ScrollView MainLayout_ScrollView1 = ((ScrollView)FindViewById(Resource.Id.MainLayout_ScrollView1));

        double scrollingSpace = MainLayout_ScrollView1.GetChildAt(0).Height - MainLayout_ScrollView1.Height;

        if(scrollingSpace <= MainLayout_ScrollView1.ScrollY)
        {
            _PageToast = Toast.MakeText(this, "You have reached to the bottom", ToastLength.Short);
            _PageToast.Show();
        }
        else
        {
            //Do things here 
        }
    }

贝娄是我得到的图像underlined red mark

here

任何帮助都将受到高度赞赏

1 个答案:

答案 0 :(得分:1)

您的活动必须实施方法OnScrollChanged,但事实并非如此。它只有OnScrollChange(最后缺少d:onScrollChange d