Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You would need to download the HTML first using something like <a href="http://developer.android.com/reference/org/apache/http/client/HttpClient.html" rel="nofollow"><code>HttpClient</code></a> to retrieve the data from the Internet (assuming you need to get it from the Internet and not a local file). Once you've done that, you can either display the HTML in a WebView, like you said, or, if the HTML is not complex and contains nothing other than some basic tags (<code>&lt;a&gt;</code>, <code>&lt;img&gt;</code>, <code>&lt;strong&gt;</code>, <code>&lt;em&gt;</code>, <code>&lt;br&gt;</code>, <code>&lt;p&gt;</code>, etc), you can pass it straight to the <code>TextView</code> since it supports some basic HTML display.</p> <p>To do this, you simply call <a href="http://developer.android.com/reference/android/text/Html.html#fromHtml%28java.lang.String%29" rel="nofollow"><code>Html.fromHtml</code></a>, and pass it your downloaded HTML string. For example:</p> <pre><code>TextView tv = (TextView) findViewById(R.id.MyTextview); tv.setText(Html.fromHtml(myHtmlString)); </code></pre> <p>The <code>fromHtml</code> method will parse the HTML and apply some basic formatting, returning a <a href="http://developer.android.com/reference/android/text/Spannable.html" rel="nofollow"><code>Spannable</code></a> object which can then be passed straight to <code>TextView</code>'s <code>setText</code> method. It even supports links and image tags (for images, though, you'll need to implement an <a href="http://developer.android.com/reference/android/text/Html.ImageGetter.html" rel="nofollow"><code>ImageGetter</code></a> to actually provide the respective Drawables). But I don't believe it supports CSS or inline styles.</p> <h2>How to download the HTML:</h2> <p>myHtmlString in the snippet above needs to contain the actual HTML markup, which of course you must obtain from somewhere. You can do this using HttpClient.</p> <pre><code>private String getHtml(String url) { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); try { HttpResponse response = client.execute(request); BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line; StringBuilder builder = new StringBuilder(); while((line = reader.readLine()) != null) { builder.append(line + '\n'); } return builder.toString(); } catch(Exception e) { //Handle exception (no data connectivity, 404, etc) return "Error: " + e.toString(); } } </code></pre> <p>It's not enough to just use that code, however, since it should really be done on a separate thread (in fact, Android might flat out refuse to make a network connection on the UI thread. Take a look at AsyncTasks for more information on that. You can find some documentation <a href="http://developer.android.com/guide/components/processes-and-threads.html#WorkerThreads" rel="nofollow">here</a> (scroll down a bit to "Using Asynctask").</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload