How to detect single Tap on the WebView
. I am displaying WebView
as a ViewPager
page. So, I can't use OnTouchListener
. And OnClickListener
doesn't work on WebView
.
Asked
Active
Viewed 1,227 times
1

Manjunath
- 2,063
- 2
- 29
- 60
2 Answers
0
If you had a link to get the event you can use something like this with shouldOverrideUrlLoading:
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
String host = null;
if (null != url && null != (host = Uri.parse(url).getHost())) {
if (host.equals("myclikableUrl")) {
clickEvent();
}
return true;
} else {
return false;
}
} catch (Exception e) {
return false;
}
}.....
});

letitthebee
- 96
- 4
-
Nope, I don't have any links in the `WebView`. I want to detect tap on the whole `WebView` – Manjunath Nov 16 '13 at 19:19
-
I don't know your view hierarchy but can't you set an onClickListener on child view of ViewPager?(I am guessing childViews are webpages?) It may work. – letitthebee Nov 16 '13 at 19:32
-
I have a ViewPager, in which few pages are WebViews. I want to detect single Tap (OR Click) on WebViews. If I handle Touch on WebView, it doesn't allow me swipe the ViewPager pages. OnClickListsner doesn't work. Also, the WebView is scrollable Horizontally & Verically. – Manjunath Nov 16 '13 at 19:42
0
Try to crete your own class that extends WebView
and here override dispatchTouchEvent(MotionEvent ev)
. Also you could add GestureDetector
and catch single tap on webview http://developer.android.com/training/gestures/detector.html

validcat
- 6,158
- 2
- 29
- 38