简体   繁体   中英

Android textview doesn't show correct characters

So I have an object that contains a couple of strings. the text in this string sometimes contains special characters like ë,ô, é, etc...

Now when I set the text in my TextView to show what is inside the string it does show the text but replaces all the special characters with ?

Any ideas how to fix this?

Note the textView is used as an listitem for a listview, and the data is extracted from a .csv file.

<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DBBD59"
android:textColor="#666666"
android:gravity="center"
android:textSize="10pt">

</TextView>

These are latin fonts which are not supported for your device.
So use custom latinfont ttf to show these font.

TextView textView = (TextView) rowView.findViewById(R.id.yourtextviewfromXml);
Typeface font = Typeface.createFromAsset(getContext().getAssets(), "latin_font_ttf_file.TTF");
textView.setText("ë,ô, é");
textView.setTypeface(font);

Note: save ttf file in assets folder.
This post may help you How to display Latin-1 characters in Android app

try to replace your special characters with their unicode.

for example replace é with &\\#223

See this http://www.codetable.net/unicodecharacters for more information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM