I'm using Html.fromHtml to get the contents of a description tag (in a feed XML) and it works fine
Description tag:
<description><![CDATA[<div class="K2FeedIntroText"><p><img style="margin: 10px; float: left;" alt="block curta" src="http://loc.grupolusofona.pt/images/stories/destaques/block%20curta.jpg" height="110" width="120" />Quatro Horas Descalço é o nome da curta-metragem, realizada por Ico Costa, que se estreia mundialmente no 7.º Festival Internacional de Cinema de Roma, nos dias 12 e 13 de novembro, em competição no Cinema XXI.</p>
]]>
But as I go look into the documentation it says:
Returns displayable styled text from the provided HTML string. Any <img> tags in the HTML will display as a generic replacement image which your program can then go through and replace with real images.
So my question is: how can i do what it says there "which your program can then go through and replace with the real image" ?
I know how to get the img url via RegEx using a Pattern, i just wanted to know how can i use the class to "go through and replace it with the image"
Please say something if i was unclear and ill try to explain it better.
EDIT:
Well, i'm trying to implement this in a simple rss reader (and trying to keep it as simple as possible code-wise)
I'm using a DOM Parser and i'm using a map = HashMap<String, Spanned>
to store the values of each child node, along with a KEY
:
map.put(KEY_DESC, Html.fromHtml(parser.getValue(e, KEY_DESC)));
In the comments of the answer i found a useful link from which i created a new Class (URLImageParser) and tried to use it like so:
map.put(KEY_DESC, htmlSpan);
Where htmlSpan
would be the result of:
this.textView = (TextView)this.findViewById(R.id.textview);
URLImageParser p = new URLImageParser(textView, this);
Spanned htmlSpan = Html.fromHtml(html, p, null);
textView.setText(htmlSpan);
I also created a android:visibility="gone"
TextView just in case it needed to store the values in a TextView (maybe i interpreted it wrong)
My original thought was that htmlSpan
was of the type Spanned
so it would fit in my HashMap just fine.
For uploading to ListView i'm using a SimpleAdapter
like so:
ListAdapter adapter = new SimpleAdapter(this, menuItems, R.layout.linhafeed,
new String[] { KEY_TITLE, KEY_DESC, KEY_PUBDATE, KEY_LINK },
new int[] { R.id.title, R.id.desc, R.id.pub, R.id.link });
Where menuItems
is ArrayList<HashMap<String,Spanned>>
Something i got wrong here ?