Xamarin C#: SimpleOnGestureListener crashes application

时间:2017-12-30 15:22:25

标签: c# android xamarin gesture gesturedetector

I'm trying to add gestures with a SimpleOnGestureListener but the application crashes with a weird error that doesn't make sense. I see this same code being used by everyone else and it works fine for them. Is this a bug with Xamarin?

Edit:

This worked for me;

Bug: developer.xamarin.com/releases/android/xamarin.android_8/… You can clean/rebuild as a workaround on Windows in order to recreate the Java classes.zip file – SushiHangover

enter image description here

using Android.App;
using Android.Widget;
using Android.OS;
using System;
using System.Collections.Generic;
using Android.Graphics;
using Android.Views;

namespace MusicPlayer
{
    [Activity(Label = "MusicPlayer", MainLauncher = true)]
    public class MainActivity : Activity
    {
        private GestureDetector _detector;

        private class GestureListener : GestureDetector.SimpleOnGestureListener
        {
            public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
            {
                return true;
            }
        }

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            var listener = new GestureListener(); //crashes here
            _detector = new GestureDetector(this, listener);
        }

        public override bool OnTouchEvent(MotionEvent e)
        {
            _detector.OnTouchEvent(e);
            return base.OnTouchEvent(e);
        }
    }
}

0 个答案:

没有答案