0

I have some conditions in which I have to change some resources in strings.xml file. Is there a way to do that programatically, without pushing an updated version of the app?

4
  • 4
    You cannot change strings.xml strings as far as I know. Instead introduce two, or more, alternative strings there and use appropriate one where needed. Commented Jan 13, 2015 at 4:57
  • 1
    every resource defined while creating an app, it is assigned an ID which can be found in R.java so until you don't have id, there is no way to modify any res file programmatically. I will suggest you should look for Shared Preferences Commented Jan 13, 2015 at 4:58
  • @harism The values cannot be known in advanced hence I cannot use alternative strings. Commented Jan 13, 2015 at 5:03
  • @JibranKhan Now that I've come to think of it, you're right. Those values are assigned at compile time and cannot be modified. Thank you for your response, I'd look for an alternate solution than modifying resource files. Commented Jan 13, 2015 at 5:05

2 Answers 2

1

No you cant. One solution is to use SharedPrefences instead.

Sign up to request clarification or add additional context in comments.

1 Comment

It answers my question, thanks! I cannot use SharedPreferences in this case. Will have to opt for a different approach int this case.
1

You cannot change the values of any resources after the app has been compiled, as the references are generated at this time.

You will have to handle this using some logic directly in your code. Something like:

if (condition) 
   set something not from resources
else
   use resource for text

1 Comment

Yeah! Those resource IDs cannot be modified at run time. I'm opting a different option here. Thank you for your response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.