OnLongClickListener not working in WebView

I have the following structure for implementing a longclicklistener. It works if I click on text in a webview that contains an html link, so I know that the structure is not completely wrong.

I deleted this link now, and the listener just no longer listens for clicks. Does anyone know this problem and have some tips?

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

...

 mywebview.setOnLongClickListener(mLongClickHandler); 
+4
android webview onlongclicklistener
Jan 11 2018-11-11T00:
source share
2 answers

I tried to clone the longclick action now. This works, but only a few times. After a while, onTouch-Event is no longer called ... 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; } }); 
+3
Jan 11 '11 at 19:43
source share

Override the onTouch method of your web view and return true for ACTION_DOWN events. So you consume your event down.

  @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: return true; } } 
+3
Jun 07 '13 at 9:21
source share



All Articles