Android Java: Several ImageParser from html string - java

I want to display the content of news with Json. I tried to do Html.fromHTML() to display the style (bold, italic etc).
Then, I want to display image from html img in my textView.
I tried this image parser but this work only for the first image and the image pass over the text.
I need help for parse image from HTML or from json before Html.fromHTML()
This is my code: (without ImagePaser, this is in the link above)
URLImageParser p = new URLImageParser(description_projet, this);
Spanned htmlSpan = Html.fromHtml(json_data.getString("contenu"), p, null);
description_projet.setText(htmlSpan);
Thanks

Related

How to show JSON volley request reponse's object (in HTML) form in textView?

I have a JSON response in which object values are in HTML form. In which i have a Paragraph, a img src and video src link. How can i parse or show the image and video onto the Activity. Any help would be appreciated.
Response I'm receiving from server(only showing one object here)
{
"description":"<p>The Sarawak Ministry of Modernisation of Agriculture</p>\n
<p><video src=\"https://myurl.biz/media/media/Nokia_X3_sample_video.3gp.3gp\" autoplay=\"autoplay\" controls=\"controls\" width=\"300\" height=\"150\">
<span id=\"mce_marker\" data-mce-type=\"bookmark\">â</span></video>
</p>\n<p><img src=\"https://myurl.biz/media/media/bird_SJhLHPo.jpg\" width=\"547\" height=\"264\" /></p>"
}
I have tried :
txtDetails.setText( Html.fromHtml(extras.getString("details"));
Actual Result I'm receiving in my text view:
The Sarawak Ministry of Modernisation of Agriculture,
​
What you're trying to do is impossible. You can't display an image/video in a TextView (this is not a browser). First, you need to parse the HTML. Then, once you have the components you can plug them in separate views. For example,
You parse the HTML (there are a lot of frameworks for that)
Get the image URL link and use Picasso (popular framework for displaying images from URLs) to display it on your Activity.
Get the paragraph and display it in a TextView
etc..

How to retrieve text from webview

I am Having an HTML file in the asset folder. The following is the way I am loading to view the HTML content. I am having a text view. Now I want to retrieve the HTML content in the string and display that in a text view using text.settext(). Please suggest me how to retrieve the content in a string.
view.loadUrl("file:///android_asset/www/index.html");

How to show Text and Images in a TextView

This is the json response below from ifeng api.
Please help me how to show text object in a TextView including images in the middle.
Use webwiev and load following json response(text witch are in html form) on webview.
Try This
First pars that data ,then get text from text param
After getting the HTML text You need to use Html.fromHtml()
If your you are targeting < Android Nougat
yourTextView.setText(Html.fromHtml("PUT YOUR HTML CODE HERE"));
If your you are targeting >= Android Nougat
yourTextView.setText(Html.fromHtml("PUT YOUR HTML CODE HERE", Html.FROM_HTML_MODE_COMPACT));
Note:-
To distinguish between Android versions use Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
Happy Coding!!
Try using TextView.setText(Html.fromHtml(...)), then using html tags in ..., but you need to implement Html.ImageGetter
Reference: https://stackoverflow.com/a/7442725/1636610
you can show image in textview as drawable like below -
tvTitle.setText("Hi");
tvTitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0);//it will show icon image on left side of the text on tvTitle text view.

Set text above image in TextView using HTML

I have a list of Strings that I add to TextViews one by one. The text is html so I can add images within the text.
So my question is... How can I add an Image so that the text appears above it. currently while using HTML.ImageGetter class text is added below the image, not above it:
Here is my Html text to be shown:
myText += "<img src='titles.png'><span> text to be above image </span>";
Please try following code as example(Html text is changed):
myText += "<div style='position: relative;width: 100%;'> <img src='titles.png'><span style='position: absolute;top: 100px;left: 0;width: 100%;'> text to be above image </span></div>";
I referred http://css-tricks.com/text-blocks-over-image/ for checking for css properties.
Hope this is helpful for you.
Thanks & Regards,
Chanchal
you can add a simple alt="texthover" to the anchor tag and it will display the text in the alt in most browsers.
But that is not as good as creating an a.hover class that would display text or a div that has text.
Does that help?

How to render image within an html dynamically?

I am having some html content with images(html+images) embedded inside it on my local drive. When i open it by double clicking on browser directly, i am able to see the content with embedded images in it.
Now i have to render this content on web browser using java apis.I am able to render html content without any issue but while rendering , image is not getting rendered , instead alt text is getting rendered on browser.
I got to know that i can not set two mime types in java code to render image as well as text on same page.I want to know how can i render html content with image inside it so that it can be rendered.
Regards.
Code added:
public void readFile() throws FileNotFoundException{
String lsFilePath = "D:\\alf3.3\\deployment\\target\\";
//String lsFilename = "/WEB-INF/message.properties";
String lsFilename = "spcontent2.html";
File loNewFile = new File(lsFilePath + lsFilename);
FileInputStream loFileInputStream = new FileInputStream(loNewFile);
FileOutputStream loFilOutputStream = new FileOutputStream(loNewFile);
}
It is fine till now but i need to know how can i render an image that is referred to in file mentioned.
For embedding an Image into html source page by adding content id into image source. This is usually practised while sending HTML emails with embedded images
Please refer following document for more info.
http://www.faqs.org/rfcs/rfc2111.html

Categories

Resources