12

In the name of performance which is better to use list of webview objects with custom array adapter defined or list of textview object again with custom adapter and html content to show in it.First I try to use webview but i think webview object is kind of heavy ui element , textview seems more lightweight.

WebView entryWebView = (WebView) findViewById(R.id.entryWebView);
                entryWebView.loadData("my hmtl formatted data", "text/html", "utf-8");

//suppose these defined in custom array adapter and filled with webview objects

TextView entryTextView = (TextView) v.findViewById(R.id.entry);
                entryTextView.setText("my html formatted data");

//and this one again in custom array adapter and filled with textview objects

Burak Dede
  • 3,725
  • 5
  • 40
  • 53

2 Answers2

10

WebView does not work well as a child of ListView, since both WebView and ListView know how to scroll. Hence, I would use TextView. Limit your HTML to the tags that Html.fromHtml() supports. Here is a list of supported tags from Android 2.1, and other versions of Android are probably similar.

With respect to performance, TextView is indeed a significantly lighter widget and would perform better in any case. You may want to cache your Html.fromHtml() output, though, so you do not have to re-do that for a given row as the user scrolls.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Yeah webView also have scrollview things might get tricky when using with ListView , and i decide to use TextView , can you give detail about caching html output ? – Burak Dede Dec 18 '10 at 20:47
  • 1
    @Burak Dede: I have not timed Html.fromHtml(), but it may not be quick. You may wish to cache the results of that call, in case the user scrolls back, so you can re-use the results. If you use a `LinkedHashMap` in LRU mode, holding `SoftReferences` to the cached data, you can ensure you will not run out of memory. – CommonsWare Dec 18 '10 at 21:17
  • @CommonsWare: In a similar situation as Dede, since TextView does not support gif animations, what is the best solution to show HTML data with embedded gif animations? – Maghoumi Dec 08 '11 at 15:36
1

As a perfromance comparison ,I tried both of them but WebView with huge data is incredibily slow , my custom adapter could not even finish drawing until user respond to interface on the other hand textview is doing pretty good as a performance , i recommend using textview unless you need to do lots of html work inside text.

Burak Dede
  • 3,725
  • 5
  • 40
  • 53