Reputation: 874
Hey guys I'm trying to get the html element that was touched by user in the webview. The scenario is for instance user touches some kind of button in the webview and the application displays the html code for the button like:
<a href="index.html"></a>
I'm already able to get the html code that the user is browsing but problem is with getting the specific html elements.
The websites the user will be browsing through will be a random sites on the internet so I can't simply put an onclick function on the button and notify the android about the click.
Any idea how would I be able to implement that?
Upvotes: 3
Views: 1367
Reputation: 2757
try this:
webview.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
WebView.HitTestResult hr = ((WebView)view).getHitTestResult();
Log.i("TAG", "getExtra = "+ hr.getExtra() + "Type= " + hr.getType());
//return true;
return false;
}
});
getExtra() returns the element which is clicked by user and getType() is used to identify which HTML element is clicked by user.
Upvotes: 2