这段代码有什么问题?
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;
}
}它给出了错误:
未为.getAction()上的类型MotionEvent定义方法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;
}
}谢谢你的帮助!
发布于 2012-12-18 12:25:57
将您的活动重命名为其他名称,它与它所需的实际MotionEvent类冲突。
发布于 2012-12-18 12:25:55
您定义的类名隐藏了android.view.MotionEvent
public class MotionEvent只需更改类名,您的问题就解决了
https://stackoverflow.com/questions/13926226
复制相似问题