Reputation: 41
I'm trying to change the values in my strings.xml using Java. It's to change certain labels in an app dynamically on certain events. Any help would be appreciated
Upvotes: 0
Views: 3280
Reputation: 2705
You might want to take a look at Java String Formatter it simply let you format a string in your string.xml but not changing the whole String , as other answers said, you can't change the value of a String in strings.xml from your java code.
Upvotes: 0
Reputation: 569
I think the best solution for your need would be to define all possible strings within the XML File. Based on the event in your application you can then choose the correct string. If the event is something like a user input then the changing the XML file is not possible. But in this case it should be fine to change the String directly without using XML references.
Upvotes: 1
Reputation: 2685
You can't change values in strings.xml as Strings are immutable (unless you do some dynamic compilation). You can have enums of Strings that can change the answer depending on passed-in variables
Upvotes: 4