views:

61

answers:

1

I have been asked to build an app that lets the user scroll massive amounts of text. The text will be several thousand of pages long. (Each page has and ID so we'll have a navigator too.)

Question: What's the best approach to have a lot of text scroll but load on demand more text as needed (up or down). I don't want to load the entire text stream, as that would take a long time. It'll need to display text in different colors and styles. eg headers in the text will be bold.

I considered the webview, but I would have to load the entire text into it wouldn't I?

Think: "Browser for the War and Peace novels"

Ideas?

+2  A: 

Assuming the text has reasonable-sized chunks (e.g., headings and paragraphs), I'd use a ListView, with rows being TextViews. You can disable the dividers, and you should be able to set the row layouts to make it appear to be a continuous stream of text (leveraging the transition between rows to give you paragraph spacing). TextView supports Spannable contents, easily obtained from HTML via Html.fromHtml().

Your ListAdapter would need to know how many rows you would need (sum of headings and paragraphs). Since you cannot hold onto all that text in RAM, in all likelihood, the ListAdapter would need to be somewhat virtual, able to get chunks of text off of flash as needed, with a modest amount cached for rapid short-range scrolling.

This approach allows you to take advantage of ListView's row recycling, to minimize RAM usage, while still giving you reasonable formatting control.

Some people have tried using WebView as rows in a ListView, if the TextView formatting is insufficient. However, I do not know how well this works, since WebView is scrollable, and putting scrollable items inside other scrollable items (ListView) is typically problematic.

CommonsWare