Android beginner: understanding MotionEvent actions
- by Dave
I am having trouble getting my activity to return a MotionEvent.ACTION_UP. Probably a beginner's error.
In LogCat, I'm only seeing the ACTION_MOVE event (which is an int value of 3). I also see the X/Y coordinates. No ACTION_DOWN and no ACTION_UP.
I looked everywhere for a solution. I found one question on a forum that seems to be the same as my issue, but no solution is proposed:
http://groups.google.com/group/android-developers/browse_thread/thread/9a9c23e40f02c134/bf12b89561f204ad?lnk=gst&q=ACTION_UP#bf12b89561f204ad
Here's my code:
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.webkit.WebView;
public class Brand extends Activity {
public WebView webview;
public float currentXPosition;
public float currentYPosition;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
webview = new WebView(this);
setContentView(webview);
webview.loadUrl("file:///android_asset/Brand.html");
}
@Override
public boolean onTouchEvent(MotionEvent me) {
int action = me.getAction();
currentXPosition = me.getX();
currentYPosition = me.getY();
Log.v("MotionEvent", "Action = " + action);
Log.v("MotionEvent", "X = " + currentXPosition + "Y = " + currentYPosition);
if (action == MotionEvent.ACTION_MOVE) {
// do something
}
if (action == MotionEvent.ACTION_UP) {
// do something
}
return true;
}
}