2

When i use the following code it gives me an error" The method onTouch(motion event) is undefined for the type object".The error is in the line"return super.onTouch(event);" i have no clue what it is.my app is about detecting gestures on a webview. gestures are detected nicely but it disables the inbuilt gestures of the webview , that's the reason i added this piece of code so that the inbuilt gestures can be detected.

webView.setOnTouchListener(new View.OnTouchListener() {

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

if any wants the whole code...here it is

package i.rock.fb;

import android.os.Bundle;
import android.app.Activity;

import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MenuInflater;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;


public class MainActivity extends Activity {

    @Override
    public boolean onCreateOptionsMenu(android.view.Menu menu) {

         super.onCreateOptionsMenu(menu);
         MenuInflater blowup=getMenuInflater();
         blowup.inflate(R.menu.main, menu);
         return true;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView webView=(WebView)findViewById(R.id.webView);
    webView.setWebViewClient(new our());
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setJavaScriptEnabled(true);

    webView.loadUrl("file:///android_asset/www/index.html");




    @SuppressWarnings("deprecation")
    final GestureDetector gestureDetector = new GestureDetector(new GestureListener());

 webView.setOnTouchListener(new View.OnTouchListener() {

     @Override
     public boolean onTouch(View v, MotionEvent event) {
                if (gestureDetector.onTouchEvent(event)) {
                    return true;
                }
               return super.onTouch(event);
            }
        });}
    final class GestureListener extends SimpleOnGestureListener {

            private static final int SWIPE_THRESHOLD = 100;
            private static final int SWIPE_VELOCITY_THRESHOLD = 100;

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

            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                boolean result = false;WebView webView=(WebView)findViewById(R.id.webView);
                try {
                    float diffY = e2.getY() - e1.getY();
                    float diffX = e2.getX() - e1.getX();
                    if (Math.abs(diffX) > Math.abs(diffY)) {
                        if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
                            if (diffX > 0) {

                                onSwipeRight();
                            } else {

                                onSwipeLeft();
                            }
                        }
                    } 

                } catch (Exception exception) {
                    exception.printStackTrace();
                }
                return result;

        }

     }




     public void onSwipeRight() {WebView webView=(WebView)findViewById(R.id.webView);
         webView.loadUrl("http://www.google.com");
        }

        public void onSwipeLeft() {WebView webView=(WebView)findViewById(R.id.webView);
         webView.loadUrl("http://www.google.com");

    }}

1 Answer 1

0

Look at this library bro, maybe i'm help you https://github.com/NikolayKolomiytsev/zTouch

2
  • While a link to more information is great, please include details of why it helps answer the question. If the link dies your answer will most likely be downvoted and/or deleted. Apr 15, 2015 at 16:32
  • Well, look, this library will be able to help this user to add processing swipe, long or double-clicks, mine is that he should not it? Now he can add processing to shift your finger up, left, down and to the right, I hope it will help him ^ _ ^ Apr 15, 2015 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.