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?
The <sup> element indicates that text should appear with superscript highlighting, or vertically raised in relationship to the surrounding text.
XML tags define the data and used to store and organize data. It's easily scalable and simple to develop. In Android, the XML is used to implement UI-related data, and it's a lightweight markup language that doesn't make layout heavy. XML only contains tags, while implementing they need to be just invoked.
String. xml file contains all the strings which will be used frequently in Android project. String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc.
I found out how
In the XML file the code should be like this :
<value column="Back" null="false">H<sub>2</sub></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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With