Reputation: 7553
Whats the problem with this code?
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;
}
}
It is giving the error:
The method getAction() is undefined for the type MotionEvent on the .getAction(). It will not let me import:
import android.view.MotionEvent;
As far as I can tell, it is the same as this working code (aside from it not letting me import the import 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;
}
}
Thanks for the help!
Upvotes: 0
Views: 2028
Reputation: 36449
Rename your Activity to something else, it is conflicting with the actual MotionEvent Class it needs.
Upvotes: 4
Reputation: 4467
The class name you defined hides android.view.MotionEvent
public class MotionEvent
Just change the class name, your problem will be solved
Upvotes: 1