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