There are many questions here in SO regarding programmatically creating UI in android, but my question is the best approach to efficiently display dynamic data.
Requirement: I want to display text data from SQLite database and display it with proper formatting. ie, Title with different color than rest of the text, different background color/drawable for some part of the text and so on.. and each row of text might be having different number of title,subtitle, body etc.. There the size of text stored is pretty large.
Problem:
1. If I create UI in xml for each text I have to create a separate layout as the number amount of text stored in database is very high this approach is won't work.
2. If I store data as HTML in database and display it in a TextView only basic formatting can be applied.
My current approach: Store data in SQLite in the form of XML with proper tags to distinguish title,subtitle, body etc.. Parse the XML data and create views programmatically for each tag with proper formatting. With this approach I can display any number of rows of data from database with a single piece of code which creates the UI.
Is there any approach better than this? Please share your suggestions.
No comments:
Post a Comment