There are a number of posts all over the internet on this topic, however none of them have been able to isolate and solve the problem.
I am trying to show some special UTF-8 encoded symbols stored in a SQLite database using a TextView, however all it shows is boxes. I understand what this means is that right font is not installed. But when I print those symbols using Arial font on Mac it works.
I am trying to use an Arial typeface on the device and the emulator.
Any advise.
It works on your Mac because the font used by your mac contains those special characters. It would be impossible to create a fontfile that contains all characters defined in unicode. Chinese fonts are a good example: none of them contain all of the ~60.000 known Chinese characters because the font file would be huge and unusable.
You could try using the font from your Mac on android (might be copyright issues - try finding a free font that contains the characters: package the (ttf) file in your application, for example in the /assets folder, and then in your application load that font with
TypeFace typeFace = Typeface.createFromAsset(assetmanager,"fontfile.ttf");
You can then use this in a TextView like so:
TextView view = (TextView) findById(R.id.mytext);
view.setTypeFace(typeFace);
If I'm understanding your situation correctly, you might want to consider the StringEscapeUtils.unescapeXml() method. It's in the common-lang.jar file available here: http://commons.apache.org/lang/
It will take encoded symbols (for example ' for an apostrophe) and get you to a proper character.
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