![](/img/trans.png)
[英]How to make the Java code to call a String from a XML file(In Android Studio)
[英]How to make the Java to call a String from a XML file(In Android Studio)
我有这个代码,我想让它成为多语言应用程序。 我想要的是使用 Strings.xml 文件中的字符串。 如何将“哥伦比亚比索”更改为字符串。
placeHolderData.add(new ExchangeListData("COP","Colombian Peso",R.drawable.colombia,time,"1"));
String string = getString(R.string.hello); // change hello to the right identifier
// then use it in your call
placeHolderData.add(new ExchangeListData("COP", string, R.drawable.colombia, time, "1"));
更多信息: https://developer.android.com/guide/topics/resources/string-resource#java
您始终可以根据用户区域设置等将R.string.hello
标识符更改为正确的语言,即R.string.es_peso
。
尝试这个
String string = getResources().getString(R.string.hello);
或者
字符串字符串 = getString(R.string.hello);
从 String.xml 获取字符串并将其添加到您想要的位置
placeHolderData.add(new ExchangeListData("COP",string,R.drawable.colombia,time,"1"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.