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?
Assuming the text has reasonable-sized chunks (e.g., headings and paragraphs), I’d use a
ListView, with rows beingTextViews. 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).TextViewsupportsSpannablecontents, easily obtained from HTML viaHtml.fromHtml().Your
ListAdapterwould 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, theListAdapterwould 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
WebViewas rows in aListView, if theTextViewformatting is insufficient. However, I do not know how well this works, sinceWebViewis scrollable, and putting scrollable items inside other scrollable items (ListView) is typically problematic.