tags:

views:

155

answers:

1

Hi, i'm trying to catch the onTouchEvent of a WebView, in order to handle actions like MotionEvent.ACTION_UP,MOVE and CANCEL. I made a simple example but did not success, however i succed with just a View. Am i missing something?

Thanks

[code]

public class HelloWebView extends Activity {

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new MyWebView(this)); }

private static class MyWebView extends WebView {

@Override public boolean onTouchEvent(MotionEvent event) { int action = event.getAction(); Log.w("TouchEvent","Touch" + action); Log.w("HitResult",this.getHitTestResult().toString()); switch (action) { case (MotionEvent.ACTION_DOWN): // Touch screen pressed break; case (MotionEvent.ACTION_UP): // Touch screen touch ended break; case (MotionEvent.ACTION_MOVE): // Contact has moved across screen break; case (MotionEvent.ACTION_CANCEL): // Touch event cancelled break; } return super.onTouchEvent(event); }

public MyWebView(Context context) { super(context); this.getSettings().setJavaScriptEnabled(true); this.loadUrl("http://www.google.com"); } }

} [/code]