Basically I need to toast a message written in Chinese to user. However I don't know how to achieve such thing. Any solution that can help me?
Asked
Active
Viewed 1,612 times
1
-
Toast? I'm guessing there's a translation error here. – ceejayoz Dec 20 '10 at 21:24
-
2Nope, Toast is correct. See here http://developer.android.com/guide/topics/ui/notifiers/toasts.html – Spencer Hakim Dec 20 '10 at 21:26
-
oh! sorry about that. since I normally use Toast class to output the message to user so I sometimes mess them up. – ForeverNights Dec 20 '10 at 21:28
2 Answers
2
I'm not an Android programmer, but doesn't this work?
Context context = getApplicationContext();
CharSequence text = "中国的网页";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
Code ripped from here.
(Apologies if that means anything offensive. I simply ripped some random characters from here).

Matt Ball
- 354,903
- 100
- 647
- 710
-
Yes, it can solve the problem "perhaps". But sometimes Eclipse or some IDE doesn't recognize Chinese character! – ForeverNights Dec 20 '10 at 21:30
-
@Silver: if your IDE doesn't recognize the characters, then it's very most likely because the file your editing isn't encoded as UTF-8. – Matt Ball Dec 20 '10 at 21:32
-
2If Eclipse is giving you trouble, make sure your files are properly encoded in a Unicode format. *Edit* - Ninja'd. – Spencer Hakim Dec 20 '10 at 21:33
-
+1 to Spencer's comment. To be clear: **UTF-8** is the encoding you want. – Matt Ball Dec 20 '10 at 21:34
1
I found my own answer. It's so simple I didn't think of that in the first place. And it always works. Under res/values/string.xml of Android project, I edit:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="sample">中国的网页</string>
</resources>
And the I retrieve the string name "sample" out of project's resource using:
this.getString(R.string.sample);

ForeverNights
- 631
- 1
- 7
- 34
-
You might want to check out how to add strings properly by e.g. looking at http://stackoverflow.com/questions/4189875/simplified-and-traditional-chinese-vs-regions . In your case you should add this to the file strings.xml in res/values-zh unless you want your application to be chinese by default.. – Manfred Moser Dec 20 '10 at 23:36