1

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?

ForeverNights
  • 631
  • 1
  • 7
  • 34

2 Answers2

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
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