Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display .rtf file inside TextView?

my app needs to display custom text saved in a bunch of .rtf files inside a TextView. I have searched in different forums and i still don't have a clear solution. It seems pretty easy right? i have developed a few apps like this in iOS and i had no problems displaying .rtf text inside a UITextView as an attributed string. I thought in Android will be easier. Thanks for your time

like image 642
Victor Pinto Avatar asked Apr 22 '14 00:04

Victor Pinto


1 Answers

It seems pretty easy right?

Not especially. Heck, even Windows largely abandoned RTF a decade or so ago.

Option #1: If you were planning on packaging the RTF in the app itself (e.g., as raw resources or assets), get rid of the RTF and use HTML in your app in the first place, using either Html.fromHtml() and a TextView or use a WebView.

Option #2: Find some Java code that can convert RTF to HTML on the fly, then proceed as in Option #1.

Option #3: Find some cross-architecture C/C++ code that can convert RTF to HTML on the fly, add that to your app via the NDK, then proceed as in Option #1.

Option #4: Roll your own RTF parser and a SpannableStringBuilder to create the formatted Spannable to load into the TextView.

like image 157
CommonsWare Avatar answered Oct 08 '22 06:10

CommonsWare