title: Android - Class Html - fromHtml - How does it work?
body: <p>I'm using Html.fromHtml to get the contents of a description tag (in a feed XML) and it works fine</p>
  
  <p>Description tag:</p>
  
  <pre><code>&lt;description&gt;&lt;![CDATA[&lt;div class="K2FeedIntroText"&gt;&lt;p&gt;&lt;img style="margin: 10px; float: left;" alt="block curta" src="http://loc.grupolusofona.pt/images/stories/destaques/block%20curta.jpg" height="110" width="120" /&gt;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.&lt;/p&gt;
  </code></pre>
  
  <p>]]></p>
  
  <p>But as I go look into the <a href="http://developer.android.com/reference/android/text/Html.html" rel="nofollow noreferrer" title="documentation">documentation</a> it says:</p>
  
  <p><code>Returns displayable styled text from the provided HTML string. Any &lt;img&gt; tags in the HTML will display as a generic replacement image which your program can then go through and replace with real images.</code></p>
  
  <p>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" ?</p>
  
  <p>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"</p>
  
  <p>Please say something if i was unclear and ill try to explain it better.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Well, i'm trying to implement this in a simple rss reader (and trying to keep it as simple as possible code-wise)</p>
  
  <p>I'm using a DOM Parser and i'm using a <code>map = HashMap&lt;String, Spanned&gt;</code> to store the values of each child node, along with a <code>KEY</code>:</p>
  
  <p><code>map.put(KEY_DESC, Html.fromHtml(parser.getValue(e, KEY_DESC)));</code></p>
  
  <p>In the comments of the answer i found a useful <a href="https://stackoverflow.com/a/7442725/1779071">link</a> from which i created a new Class (URLImageParser) and tried to use it like so:</p>
  
  <p><code>map.put(KEY_DESC, htmlSpan);</code></p>
  
  <p>Where <code>htmlSpan</code> would be the result of:</p>
  
  <pre><code>this.textView = (TextView)this.findViewById(R.id.textview);
  URLImageParser p = new URLImageParser(textView, this);
  Spanned htmlSpan = Html.fromHtml(html, p, null);
  textView.setText(htmlSpan);
  </code></pre>
  
  <p>I also created a <code>android:visibility="gone"</code> TextView just in case it needed to store the values in a TextView (maybe i interpreted it wrong)</p>
  
  <p>My original thought was that <code>htmlSpan</code> was of the type <code>Spanned</code> so it would fit in my HashMap just fine.</p>
  
  <p>For uploading to ListView i'm using a <code>SimpleAdapter</code> like so:</p>
  
  <pre><code>    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 });
  </code></pre>
  
  <p>Where <code>menuItems</code> is <code>ArrayList&lt;HashMap&lt;String,Spanned&gt;&gt;</code></p>
  
  <p>Something i got wrong here ?</p>