views:

53

answers:

1

is there any way to have an html file (i.e. an html template) be a resource in android? I'd like to reference it in a similar way that i store strings in the res/values/strings.xml. However, when i do this, it appears the HTML is not getting rendered correctly when i use myTextView.setText(Html.fromHtml(MessageFormat .format(getResources().getString(R.string.myHtmlFile), ...)

+1  A: 

Hi,

You can place raw HTML or other format files in /res/raw or /assets directory of your project. You can access the first with this method, and the second with this.

ognian
so this works, but then i have to go thru the pain of using an input stream. is there a simple way that you know of to just get the contents of a file into a string? in C#, you can just say `String blah = new StreamReader(myInputStream).readToEnd()`isn't there anyway to do that in android/java?
Ben
Write a static method somewhere that takes InputStream and returns a String. Wrap the stream with BufferedInputStream, and append the data to a StringBuilder until exhausted.
ognian
blech. i hate re-inventing the wheel, i added a ref to apache.commons.io thanks though... :)
Ben