tags:

views:

1082

answers:

1

I am having trouble getting my activity to generate 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;
  }

}
+2  A: 

Your problem is that you're doing this from within a WebView. WebViews have built-in touch control to allow the user to scroll the page around, and that must be interfering with you receiving the MotionEvents. It would seem that you will need to use a different View. For example, I just ran your code making the following substitution:

TextView tv = new TextView(this);
setContentView(tv);

instead of

webview = new WebView(this);
setContentView(webview);
webview.loadUrl("file:///android_asset/Brand.html");

and everything else worked. Note: I used a TextView as the whole view just for simplicity. This works on ViewGroups like LinearLayouts, RelativeLayouts, custom Views with canvases etc. It just seems that WebViews are special. (I was also only receiving ACTION_MOVE when using the WebView.) So, I hope you can get away with using something other than a WebView!

Steve H
Wow thanks for the reply!It makes things a bit more complicated but at least it will WORK! :)
Dave