这段代码有什么问题?
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;
}
}
谢谢您的帮助!