Load A Div Into A Webview On Android
I have an Android app, which contains a WebView, and I would like to display in it not a webpage, but only a div from that webpage. I should mention that I do not have access to th
Solution 1:
I would recommend Jsoup. It's larger than tagsoup but provides inbuilt functionality to pull the HTML from the URL and is super easy to use. For example if you want to pull a div
with id example
you would do the following:
Document doc = Jsoup.connect(url).get();
Elements ele = doc.select("div#example");
Then to load the HTML you've extracted into your web view you would do:
Stringhtml= ele.toString();
Stringmime="text/html";
Stringencoding="utf-8";
webView.loadData(html, mime, encoding);
Solution 2:
You'll need to load the HTML of the page yourself, extract the div contents and pass it to the WebView as a string. You may find an HTML parser library (e.g. tagsoup) useful for this.
Post a Comment for "Load A Div Into A Webview On Android"