Java 如何通过传递string';从方法访问R.string.xxx资源;xxx和x27;作为该方法的参数?

Java 如何通过传递string';从方法访问R.string.xxx资源;xxx和x27;作为该方法的参数?,java,android,Java,Android,我的res/values/strings.xml中有许多字符串元素 因此,我需要一个方法getString(stringabc)从strings.xml检索字符串: public String getString(String abc){ // abc = address1 String result; result = context.getResources().getString(R.strings.+abc); } 如何基于参数中的字符串访问此方法中的字符串元素?请

我的
res/values/strings.xml中有许多字符串元素

因此,我需要一个方法
getString(stringabc)
strings.xml
检索字符串:

public String getString(String abc){ // abc = address1

    String result;

    result = context.getResources().getString(R.strings.+abc);
}
如何基于参数中的字符串访问此方法中的字符串元素?

请尝试以下操作:

 String abc="StringId";
 int resID = getResources().getIdentifier(abc, "string",  getPackageName()); 
Resources res = this.getResources(); 
 int resID = res.getIdentifier(imagename, "drawable", this.getPackageName());
Resources res = this.getResources(); 
 int resID = res.getIdentifier(imagename, "drawable", this.getPackageName());