Javascript 从strings.xml中选择不同的值
在mystrings.xml中,我有以下内容Javascript 从strings.xml中选择不同的值,javascript,android-studio,Javascript,Android Studio,在mystrings.xml中,我有以下内容 <string name="alphabet">ABCDEFGHIJKLMNOPQRSTUVWXYZ</string> <string name="alphabet_numbers">123456789</string> 它不会返回字符串字母表。我需要将字符串字母表用于我的MainActivity类,字符串资源没有问题。您应该在if语句之外定义返回变量 public String returnAlph
<string name="alphabet">ABCDEFGHIJKLMNOPQRSTUVWXYZ</string>
<string name="alphabet_numbers">123456789</string>
它不会返回字符串字母表。我需要将字符串字母表用于我的MainActivity类,字符串资源没有问题。您应该在if语句之外定义返回变量
public String returnAlphabet(){
String mychoice = "yes";
String alphabet = null;//define string here
if (mychoice.equals(mychoice)){
alphabet = getResources().getString(R.string.alphabet);
}else{
alphabet = getResources().getString(R.string.alphabet_numbers);
}
return alphabet;
}
我需要用if语句获取字母表\u编号,但它不起作用,和它不返回字符串字母表之间存在矛盾你能解释一下你的需求到底是什么吗?很好的重构建议。但根据逻辑,这将永远不会返回字母数字的值。让我们看看作者是否对逻辑有其他想法。
public String returnAlphabet(){
String mychoice = "yes";
String alphabet = null;//define string here
if (mychoice.equals(mychoice)){
alphabet = getResources().getString(R.string.alphabet);
}else{
alphabet = getResources().getString(R.string.alphabet_numbers);
}
return alphabet;
}