I have an HTML string of data that i parse from an ATOM Feed. Obviously there are references to images inside, that I'd like to show on a WebView. But using
webview.loadDataWithBaseURL("", data,"text/html", "utf-8","");
only the text is displayed and the images are not shown.
What I am missing?
Thank you in advance.
You are not passing the BASE URL, you are passing the emptry string. As you can see in the docs loadDataWithBaseURL() is expecting as the first parameter the Base URL of your Html Data. So what you should have is something like this :
webview.loadDataWithBaseURL("www.mypage.html",data,"text/html","utf-8",null);
Related
The response of a web service is the following :
<span style="color:#DDFFEE;">You have to pay you bil before <b>12 june 2012</b> for your informations.</span></br></br> You have already a large time.
I want to display this in a TextView.
I can't just simply put the response below in a String and applicate
myTextView.setText(Html.fromHtml(response));
It doesn't work because it can't be a String.
How can I do this dynamically please ?
You just need to put the String you get as a response, inside the fromHtml call, if it's not a String, maybe you just need to append .toString() to it, to get a String..
textView.setText(Html.fromHtml("<h2>This is HTML</h2>"));
You need to use Html.fromHtml() to use HTML in your XML Strings. Simply referencing a String with HTML in your layout XML will not work.
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
here : Similar question
I want to load string in webview , below is the String :-
Hi,
Hw are u ?
Thanks,
When i use loadData of web view it displays the string in single line , spaces are removed.
I want it in same format , hw is it possible ?
If you are using a webview, you should format the string into html.
I think that you already have a html file., if that is the case you only need put a format in the file.
Hi,<br>
Hw are u ?<br>
My data in db is stored in html format along with image tags in it. So when I am getting the data from database I am removing the html tags and setting it to textview. My problem is even after removing the html tags, there is a small square box displaying in the emulator indicating that there is some image. How can I remove those square box in emulator which is an indication of image in that html data? Help me regarding this...
Thanks in advance
My Code:
textView.setText(Html.fromHtml(htmlString));
You could do a regex replace <img.+?> on htmlString.
textView.setText(Html.fromHtml(htmlString.replaceAll("<img.+?>", "")));
Untested
since images can look like:
<img ...></img>
and
<img... />
This solution will match both cases:
String htmlBody = htmlString.replaceAll("<img.+/(img)*>", "");
textView.setText(Html.fromHtml(htmlBody));
None of the answers are able to remove all possible img tags.
The most appropriate answer would be
String htmlBody = htmlString.replaceAll("(<(/)img>)|(<img.+?>)", "");
It will remove and tags both. And not remove any content between two images.
hi have a look on this example
String temp="<img>helloo</img><b> this is test</b>";
temp= temp.replace("<img>", "");
temp= temp.replace("</img>", "");
textView.setText(Html.fromHtml(temp));
I am fetching few html content from my server for which I am using JSON parsing. But this converts my html content to unicode values.
For Eg: <p>Spend minimum $10 (in a single same-day receipt) at any outlet<\/p> is getting converted to,
;p>Spend minimum $10 (in a single same-day receipt) at any outlet </p>
Now if I try to set this to my WebView it displays with HTML tags itself. If I try to encode the data using TextUtils.encode it displays the text with unicode values.
Can anyone help me with this.
How should I fetch a HTML content and display it in WebView?
I am not getting your question exactly but, If you want to load HTML in web view in you can use
webView.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
and if you want to convert < and > like notation you can use Jsoup Library
Guys thanks for your help. But I have solved this issue myself. I have elaborated my way of solving the issue.
What I did is,
1)convert the unicode value to Spanned like this,
Spanned ss=Html.fromHtml(;p>Spend minimum $10 (in a single same-day receipt) at any outlet </p>");
2)Now convert this Spanned to String like this,
String tempString=ss.toString();
3)And now set this to WebView which solved the problem,
webView.loadData(tempString, "text/html","UTF-8");
Actually this isn't JSON encoder converts data to HTML entities but some other layer, before it passed to JSON encoder.
JSON have nothing to do with HTML tags, usually only quotes encoded by parser (Unicode is supported by most parsers).
You probably need to change the way data is returned by server, to omit encoding of HTML tags braces to HTML entities or decoding entities backin your app.
Update:
To decode HTML entities used in HTML tags (and others too) you may use StringEscapeUtils.unescapeHTML()
To show the HTML page inside the Webview why you require the JSON. create web view inside the XML and write below code Inside the Activity you can see the HTML page.
webView = (WebView)findViewById(R.id.webView);
FrameLayout mContentView = (FrameLayout) getWindow().
getDecorView().findViewById(android.R.id.content);
final View zoom = this.webView.getZoomControls();
mContentView.addView(zoom, ZOOM_PARAMS);
zoom.setVisibility(View.GONE);
webView.loadUrl("http://www.google.co.in/");
I'm new to Android programming.
I would like to know if I can load a certain part of a website into webview? The website is made from CSS. It contains headers and buttons that I do not want to be displayed into the webview. I would only like to display the contents in the website, like images and texts. Is this possible? If so, how?
Many thanks in advance!!!
You can use the public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl) method to load a customised html, maybe your app can get the html from the site, modify it, and loadDataWithBaseUrl then.