Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 693
xSooDx Avatar asked Apr 04 '13 17:04

xSooDx


People also ask

How do you add a superscript in XML?

The <sup> element indicates that text should appear with superscript highlighting, or vertically raised in relationship to the surrounding text.

Can we use XML for Android?

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.

What is Strings XML file in Android?

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.


1 Answers

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"

like image 133
xSooDx Avatar answered Oct 18 '22 15:10

xSooDx