查看/ motionEvent不能被解析为一个变量刷卡 [英] view/motionEvent cannot be resolved to a variable swipe

查看:187
本文介绍了查看/ motionEvent不能被解析为一个变量刷卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个code从另一个计算器问题:

I have got this code from another stackoverflow question:

import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class OnSwipeTouchListener implements OnTouchListener {

    private final GestureDetector gestureDetector = new GestureDetector(new GestureListener());

    public boolean onTouch(final View v, final MotionEvent event) {
        super.onTouch(view, motionEvent);
        return gestureDetector.onTouchEvent(event);
    }

    private final class GestureListener extends SimpleOnGestureListener {

        private static final int SWIPE_THRESHOLD = 100;
        private static final int SWIPE_VELOCITY_THRESHOLD = 100;

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            boolean result = false;
            try {
                float diffY = e2.getY() - e1.getY();
                float diffX = e2.getX() - e1.getX();
                if (Math.abs(diffX) > Math.abs(diffY)) {
                    if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
                        if (diffX > 0) {
                            onSwipeRight();
                        } else {
                            onSwipeLeft();
                        }
                    }
                } else {
                    if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
                        if (diffY > 0) {
                            onSwipeBottom();
                        } else {
                            onSwipeTop();
                        }
                    }
                }
            } catch (Exception exception) {
                exception.printStackTrace();
            }
            return result;
        }
    }

    public void onSwipeRight() {
    }

    public void onSwipeLeft() {
    }

    public void onSwipeTop() {
    }

    public void onSwipeBottom() {
    }
}

在我贴code到Eclipse中,我得到super.onTouch(查看,motionEvent)错误; 。
如果这可以帮助你的编译器遵从性级别设置为1.6。
我试图重新启动日食,删除和导入该项目,但没有成功。
感谢和新年快乐!

After I paste the code into eclipse, I get error on super.onTouch(view, motionEvent); . The compiler compliance level is set to 1.6 if that helps you. I tried restarting eclipse, deleting and importing the project but without success. Thanks and a happy new year!

推荐答案

您变量不匹配:

//  You need to use these names   *                    *****
public boolean onTouch(final View v, final MotionEvent event) {
    super.onTouch(v, event);

不过,要实现OnTouchListener所以实际上这行什么也不做。你可以将其删除。

But you are implementing OnTouchListener so really this line does nothing. You can remove it.

这篇关于查看/ motionEvent不能被解析为一个变量刷卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆