How can I programmatically reference something in / values ​​/ strings.xml?

I had some elements in my strings.xml file that I want to change programmatically, and initially I did it through a call setText();, but now I'm trying to translate my application into another language, which means that everything must be installed in the strings file. xml. Is it possible to put all the text for my application in the strings.xml file and programmatically change it using links to line names, instead of using the call to the setText () function? for example, how would I refer to "GrandTotal"?

<string name="GrandTotal">Grand Total:</string>
<string name="choose_prompt">Choose a Mode</string>
+3
source share
4 answers

you can use setText(R.string.GrandTotal);

resId, getString(R.string.GrandTotal);

+16

resourceIds real int, ,

String s = getResources().getString( R.string.grand_total );

ui resourceIds, @Keyboardsurfer

+6

Try this way. Hope this helps you.

setText(getResources().getString(R.string.GrandTotal));
+1
source

In Activity:

String str = getString(R.string.choose_prompt);

or

String str = this.getString(R.string.choose_prompt);
0
source

All Articles