[英]Selecting a value from android resource
In javascript, we can conditionally select a value from a object using a variable as, 在javascript中,我们可以使用变量有条件地从对象中选择一个值,
var myObj = {"a": "Val1", "b": "Val2", "c": "Val3"};
var key = "a";
var val = myObj[key];
What is the similar method to select the value from a string resource file in android using variable string name? 使用可变字符串名称从android中的字符串资源文件中选择值的相似方法是什么?
We can select a string as R.string.mystring
in android and from a java public class 我们可以从Android和Java公共类中选择一个字符串作为
R.string.mystring
public class myarray {
public static final String test = "Test";
public myarray(){
}
}
as String val = myarray.test;
如
String val = myarray.test;
but we wanted a method something similar to above javascript. 但我们想要一种类似于上述javascript的方法。
A translation of your javascript code is the following: 您的javascript代码的翻译如下:
HashMap<String, String> myObj = new HashMap<String, String>();
myObj.put("a","Val1");
myObj.put("b","Val2");
myObj.put("c","Val3");
String key = "a";
String value = myObj.get(key);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.