简体   繁体   English

如何使 Java 从 XML 文件中调用字符串(在 Android Studio 中)

[英]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.

相关问题 如何使Java代码从XML文件调用String(在Android Studio中) - How to make the Java code to call a String from a XML file(In Android Studio) 如何从 java 或 Android 中的字符串制作 XML 文档? - How to make XML document from string in java or Android? 显示来自 Java 文件而不是 XML 文件的文本 (Android Studio) - Display text from Java file instead of XML file (Android Studio) 如何在xml / java中使按钮颜色可变(android studio) - how to make button color variable in xml/java (android studio) 如何在java中的android studio中使用xml格式字符串解析数据 - how to xml format string parsing data in android studio in java 如何在没有xml文件的情况下在android studio中制作100个按钮? - How to make 100 buttons in android studio without xml file? XML解析:如何将XML文件中的下一个元素放入字符串中? (Java / Android) - XML-Parsing: How put next Elements from XML-File into String? (Java / Android) 如何将整数从Java文件发送到XML文件夹? (Android Studio) - How can I send a integer from my Java file to my XML folder? (Android Studio) 如何通过Java / Android Studio将节点和值保存到xml文件 - How to save nodes and values to an xml file through java /Android Studio 如何在android studio中调用已编译jar文件的java类? - How to call java classes of a compiled jar file within android studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM