Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Special chars are replaces with a square in android app

In my android app I make a simple toast

Toast.makeText(
        parent.getApplicationContext(),
        parent.getResources().getIdentifier(result, "string",
        parent.getPackageName()), Toast.LENGTH_LONG).show();

This

parent.getResources().getIdentifier(result, "string", parent.getPackageName())

retrieves a string whose name matches result from strings.xml. I have a strings.xml file for english and german language. The problem is that special chars in german language like Ü Ö Ä are not displayed correctly. They are replaced by a square symbol.

The strings.xml are utf-8 encoded.

Where is the problem and how can I fix it?

like image 365
UpCat Avatar asked Jan 05 '12 11:01

UpCat


1 Answers

ArtWorkAD,

It appears as though your problem is being caused by the fact that the Toast.makeText() method is not using the correct Charset when pulling your special characters from the resources.

I suggest as a debugging step you pull the string down from the resources independantly and use the

Toast.makeText(Context context, CharSequence text, int duration).show();

overload to render your text. This way you can confirm that the text is what you expect and narrow down your problem.

like image 82
Adam G. Carstensen Avatar answered Oct 05 '22 07:10

Adam G. Carstensen