Reputation: 21
I need to assign a utf-8 character to string array. How could I do this? I was just simple pasting it into eclipse from wordpad but some characters are shown as rectangles for example:
equations[4][2] = "N=N₀2";
In this case it is subscript 0; This doesn't work (utf-8 code taken only as an example):
equations[4][2] = "N=N"+char(U+00BA)+"2";
Upvotes: 2
Views: 2052
Reputation: 3433
Not all Unicode values are natively supported on Android. If you are trying to set a subscript or superscript to the text in a TextView
or on a Button
or some similar View
with text, you can use HTML like this:
(TextView)findViewById(R.id.textView).setText(Html.fromHtml("X<sup>2</sup>"));
This is handy and easy for subscripts and superscripts. For other Unicode characters, if it doesn't display in Android, then it probably just means that it is not supported on the built-in fonts. In that case, you would need to import your own font.
Summary of Options: You can store the subscript 0 value in your array however you like, but once you need to display it in text on the device, you need to 1) Use HTML, OR 2) Import your own font.
Also, welcome to StackOverflow! Your question was well constructed and formatted, but I would also recommend looking at the FAQ to see the ins and outs of accepting answers. You accept an answer that has solved your question to your desire by clicking the check box next to that answer. This gives the person credit and helps future viewers. Happy coding!
Upvotes: 1
Reputation: 610
Convert your file to UTF8 and write the character in the code like other caractere.
Upvotes: 0