DarkLeafyGreen
DarkLeafyGreen

Reputation: 70406

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?

Upvotes: 11

Views: 2673

Answers (3)

Adam G. Carstensen
Adam G. Carstensen

Reputation: 185

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.

Upvotes: 2

Tofeeq Ahmad
Tofeeq Ahmad

Reputation: 11975

Instead of using Toast Message , you can use custom dialog in which you can have on TextView to show this string.Now use

    TextView textView=new TextView(this);
    textView.setText(Html.fromHtml("your string"));

Hope this work for you but have not tried

Upvotes: 0

Shishir Shetty
Shishir Shetty

Reputation: 2049

Please read the android documentation carefully : http://developer.android.com/resources/tutorials/localization/index.html

Upvotes: 0

Related Questions