簡體   English   中英

如何使 Java 從 XML 文件中調用字符串(在 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM