Superscript and Subscript in Android App XML

xSooDx picture xSooDx · Apr 4, 2013 · Viewed 12.4k times · Source

I am parcing data from an XML file which has subscript and superscript characters in them which i got from the character map. Like so:

<value column="Back" null="false">H₂</value>

but when i display it on a textview in android it gives me this 'Hâ,,'

how can i fix this and display it properly in my app?

Answer

xSooDx picture xSooDx · Apr 6, 2013

I found out how

In the XML file the code should be like this :

<value column="Back" null="false">H&lt;sub&gt;2&lt;/sub&gt;</value>

So that the parced string value is "H<sub>2</sub>" then in the java code :

TextView textview.setText(Html.fromHtml(YourString);

and for superscript use "sup" instead of "sub"