Question

I currently have a GestureDetector on a webView that I want to respond to double taps. However, the webView then ignores all single taps - presumably I have overridden this behaviour too.

I am looking for:

  • Double taps to be detected by my code and dealt with by my activity
  • Regular taps to be dealt with as normal by the WebView

Here's what I have so far:

final WebView web = (WebView) findViewById(R.id.webView1);
WebViewClient webrules = new WebViewClient(){
        public boolean shouldOverrideUrlLoading(WebView web,String url){
            return false;
        }
    };
    web.setWebViewClient(webrules);
    WebSettings webSettings = web.getSettings();
    webSettings.setJavaScriptEnabled(true);

 

final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            Log.d("**APP**", "Double Tap event");
            return true;
        }

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }
    });
    gestureDetector.setIsLongpressEnabled(true);

    web.setOnTouchListener(new OnTouchListener(){

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return gestureDetector.onTouchEvent(event);
        }

    });

How can I leave the normal single taps to the webView to deal with?

Was it helpful?

Solution

Try returning false in your onDown method. Returning true "means" that the event has been consumed, and is therefore not passed on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top