适用于Android的Motion事件

时间:2012-12-18 04:22:45

标签: android eclipse motionevent

这段代码有什么问题?

package com.evorlor.samplecode;

import android.app.Activity;

public class MotionEvent extends Activity {

    public boolean onTouchEvent(MotionEvent me) {
        int i = me.getAction();

        switch (i) {

        case MotionEvent.ACTION_DOWN:
            // When your finger touches the screen

            break;

        case MotionEvent.ACTION_UP:
            // When your finger stop touching the screen

            break;

        case MotionEvent.ACTION_MOVE:
            // When your finger moves around the screen

            break;
        }

        return false;
    }

}

它给出了错误:

对于MotionEvent类型,未定义方法getAction() 在.getAction()上。它不会让我导入:

import android.view.MotionEvent;

据我所知,它与这个工作代码相同(除了它不让我导入导入android.view.MotionEvent;):

package com.evorlor.counter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

public class Counter extends Activity {

    private static int count = 0;
    private static int hiCount = 0;
    private static boolean capCount = false;
    public static boolean resetCount = false;
    public static boolean askReset = false;

    public boolean onTouchEvent(MotionEvent me) {
        if (me.getAction() == MotionEvent.ACTION_UP) {
            count++;
        }

        onCreate(null);

        return false;
    }
}

感谢您的帮助!

2 个答案:

答案 0 :(得分:4)

将Activity重命名为其他内容,它与所需的实际MotionEvent类冲突。

答案 1 :(得分:1)

您定义的类名隐藏了android.view.MotionEvent

public class MotionEvent

只需更改班级名称,您的问题就会解决