Reputation: 2773
In javascript, we can conditionally select a value from a object using a variable as,
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?
We can select a string as R.string.mystring
in android and from a java public class
public class myarray {
public static final String test = "Test";
public myarray(){
}
}
as String val = myarray.test;
but we wanted a method something similar to above javascript.
Upvotes: 0
Views: 53
Reputation: 15741
A translation of your javascript code is the following:
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);
Upvotes: 2