开发者

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开发者_如何学JAVA(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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜