我的中有很多字符串元素 res/values/strings.xml
所以,我想要一种getString(String abc)
从strings.xml
以下方法中检索字符串的方法:
public String getString(String abc){ // abc = address1
String result;
result = context.getResources().getString(R.strings.+abc);
}
Run Code Online (Sandbox Code Playgroud)
如何根据参数中的String访问此方法中的字符串元素?
public String getString(String abc){ // Ex. abc = "address1"
int resID = getResources().getIdentifier(abc, "string", getPackageName());
return context.getResources().getString(resID);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1332 次 |
最近记录: |