onLongClickListener does not work on WebView
Asked Answered
A

2

5

I have the following struktur to implement an longclicklistener. It works if I click on a text on the webview which contains a html-link, so I know the structure is not completely wrong.

I removed this link now and the listener just doesn't listen to clicks anymore. Does anybody know this problem and have some advices?

    private View.OnLongClickListener mLongClickHandler = new View.OnLongClickListener()   {
    @Override
    public boolean onLongClick(View view) {
        ...
        return true;
    }
};

...

mywebview.setOnLongClickListener(mLongClickHandler);
Adiana answered 11/1, 2011 at 15:16 Comment(3)
The event is probably being consumed by the webview content before it gets to the actual webview.Dixon
The webview does nothing but showing some text. And with html-links inside the text a long click on this works.Adiana
I have a similar problem on HTC Desire (Android 2.2.2): OnLongClickListenerniver never fired except when the click happens on a link. Note that this problem never happens on a Galaxy S2 (works with Android 2.3.3).Buoyancy
A
3

I tried now to clone the longclick action by myself. This works but only a few times. After a certain time, the onTouch-Event is not called anymore... Suggestions?

private Runnable copyTextAfterDelay=new Runnable() {
    public void run() {
        ...
    }
};

...

        myWebView.setOnTouchListener(new View.OnTouchListener() { 
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) { 
                    case MotionEvent.ACTION_DOWN:  
                        mTimerHandler.removeCallbacks(copyTextAfterDelay);
                        mTimerHandler.postDelayed(copyTextAfterDelay,1000);
                        break;
                    case MotionEvent.ACTION_UP: 
                        mTimerHandler.removeCallbacks(copyTextAfterDelay);
                        break;
                    case MotionEvent.ACTION_MOVE:
                        mTimerHandler.removeCallbacks(copyTextAfterDelay);
                        break;
                }
                return false;                  
            }
            });
Adiana answered 11/1, 2011 at 19:43 Comment(0)
A
3

Override onTouch methode of your webview and return true for ACTION_DOWN events. Thereby you consume your down event.

  @Override
  public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) { 
         case MotionEvent.ACTION_DOWN:  
            return true;
      }
   }
Antony answered 7/6, 2013 at 9:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.