onLongClickListener does not work on WebView

前端 未结 2 1063
别跟我提以往
别跟我提以往 2020-12-21 00:20

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 comp

相关标签:
2条回答
  • 2020-12-21 01:09

    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;                  
                }
                });
    
    0 讨论(0)
  • 2020-12-21 01:24

    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;
          }
       }
    
    0 讨论(0)
提交回复
热议问题