Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which one to use WebView or TextView in a list with HTML data in it?

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

like image 417
Burak Dede Avatar asked Dec 18 '10 17:12

Burak Dede


2 Answers

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.

like image 73
CommonsWare Avatar answered Nov 02 '22 07:11

CommonsWare


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.

like image 41
Burak Dede Avatar answered Nov 02 '22 06:11

Burak Dede