|
查看: 972|回复: 3
|
midlet choiceGroup疑问!!!
[复制链接]
|
|
|
开始时,依据
locale显示英文或中文。接下来我希望 依据User在choiceGroup里选择语言,按show显示英文或中文,要如何做到?谢谢
public void startMIDlet() {
String locale = System.getProperty("microedition.locale");
locale = locale.replace('-', '_');
String classname = "com.test.language.Resource" + locale.toUpperCase();
try {
lang = (LanguageBase) Class.forName(classname).newInstance();
}
catch(Throwable t) {
System.out.println("This language is probably not supported!!!");
classname = "com.test.language.ResourceEN_US";
}
try {
lang = (LanguageBase) Class.forName(classname).newInstance();
}
catch(Throwable t) {
System.out.println("Can't find the English language resources!!!");
}
switchDisplayable(null, getMainForm());
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public Form getMainForm() {
if (mainForm == null) {
showCommand = new Command(“show”, Command.OK, 0);
mainForm = new Form(“Welcome”, new Item[] { getLangGroup() });
mainForm.addCommand(getExitCommand());
mainForm.addCommand(showCommand);
mainForm.setCommandListener(this);
}
return mainForm;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
public ChoiceGroup getLangGroup() {
if (langGroup == null) {
langGroup = new ChoiceGroup("Language:", Choice.EXCLUSIVE);
langGroup.append("English", null);
langGroup.append("中文", null);
langGroup.setSelectedFlags(new boolean[] { false, false });
}
return langGroup;
} |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 26-11-2009 04:33 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 26-11-2009 06:17 PM
|
显示全部楼层
我 教你 好了 。。。。
首先 , 你 要有 2 个 PROPERTIES FILE , 一个 是 STORE 英文的 , 一个 是 STORE 中文的 。。
labelMe = Me (英文)
labelMe = 我 (中文)
然后 , 就去 读 你的 PROPERTIES , 就 可以了 。。。。。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 26-11-2009 06:44 PM
|
显示全部楼层
谢谢你的回复,我想你误会了我想表达的。
其实,Midlet一开始时,依据以下Code(ResourceEN_US or ResourceZH_CN),成功显示不同的语言。
public void startMIDlet() {
String locale = System.getProperty("microedition.locale");
//String locale = "zh_CN";
locale = locale.replace('-', '_');
String classname = "com.test.language.Resource" + locale.toUpperCase();
try {
lang = (LanguageBase) Class.forName(classname).newInstance();
}
catch(Throwable t) {
classname = "com.test.language.ResourceEN_US";
}
try {
lang = (LanguageBase) Class.forName(classname).newInstance();
}
catch(Throwable t) { }
switchDisplayable(null, getMainForm());
}
但我的MainForm有choiceGroup让User选择语言。当user选择English时,按Login键(例如要显示Error Alert 是英文的;返之,选择"中文" 就马上显示Error Alert是中文的)。
我尝试用以下code做,一开始选择English时按Login键,Error Alert 成功显示英文; 然后我马上选择中文,再按Login键,它还是显示英文;但当我按第一次没有按过的键(例如Exit,Confirmation Alert display),它是显示中文的。
public void itemStateChanged(Item item)
{
if (item == langGroup){
switch (langGroup.getSelectedIndex ()){
case 1:
try {
lang = (LanguageBase) Class.forName("com.luckysms.language.ResourceZH_CN").newInstance();
}catch(Throwable t) {}
break;
default:
try {
lang = (LanguageBase) Class.forName("com.luckysms.language.ResourceEN_US").newInstance();
}catch(Throwable t) {}
break;
} } }
希望你可以明白我所表达的。也希望你能帮我,万分感激!!! |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|