Guillaume Guillaume - 1 year ago 117
Android Question

Android Webview Click

I have a

and I sent a URL. The page display is okay, but I cannot interact with the page displayed. I cannot click the buttons, I have just a front ...
Do you have an idea of the problem?

My code :

protected void onCreate(Bundle savedInstanceState) {
WebView myWebView = (WebView) findViewById(;
myWebView.setWebViewClient(new WebViewClient());

Answer Source

You can add onclick to webview with the following method:

webView.setOnTouchListener(new View.OnTouchListener() {

        public final static int FINGER_RELEASED = 0;
        public final static int FINGER_TOUCHED = 1;
        public final static int FINGER_DRAGGING = 2;
        public final static int FINGER_UNDEFINED = 3;

        private int fingerState = FINGER_RELEASED;

        public boolean onTouch(View view, MotionEvent motionEvent) {

            switch (motionEvent.getAction()) {

                case MotionEvent.ACTION_DOWN:
                    if (fingerState == FINGER_RELEASED) fingerState = FINGER_TOUCHED;
                    else fingerState = FINGER_UNDEFINED;

                case MotionEvent.ACTION_UP:
                    if(fingerState != FINGER_DRAGGING) {
                        fingerState = FINGER_RELEASED;

                        // Your onClick codes
                       Toast.makeText(WebActivity.this,"Click Detected",Toast.LENGTH_LONG).show();            

                    else if (fingerState == FINGER_DRAGGING) fingerState = FINGER_RELEASED;
                    else fingerState = FINGER_UNDEFINED;

                case MotionEvent.ACTION_MOVE:
                    if (fingerState == FINGER_TOUCHED || fingerState == FINGER_DRAGGING) fingerState = FINGER_DRAGGING;
                    else fingerState = FINGER_UNDEFINED;

                    fingerState = FINGER_UNDEFINED;


            return false;

If there is a button inside webview, the webpage that you are displaying inside the webview will handle that.You cannot get that callback.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download