Search code examples
androidxmlsubscriptsuperscript

Superscript and Subscript in Android App XML


I am parsing 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?


Solution

  • 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"