Changing value of R.String Programmatically

31,986

Solution 1

You can't change strings.xml dynamically since it's a compiled resource. There are other mechanisms for saving data in Android, here's a nice post that covers this topic: Data Storage. Hope this helps.

Solution 2

If you need to save small amounts of String information you should be using SharedPreferences that's exactly what it's for :)

Share:
31,986
Falcon165o
Author by

Falcon165o

I'm an all around good guy. I develop Automation for Android Environments in an Agile-Scrum environment. Strong Programming Languages: Java, C# Database Skills: MySQL, SQL, T-SQL Currently Playing: Starcraft II: Wings of Liberty, Starcraft II: Heart of the Swarm, Diablo III Retired Games: Starcraft, Starcraft: Brood War, Diablo II, Warcraft II + III, Command & Conquer, Tiberian Sun, Age of Empires I + II, Skyrim Bachelors of Science in Computer Science, 2011

Updated on July 11, 2022

Comments

  • Falcon165o
    Falcon165o almost 2 years

    Can you change the values of a R.string programmatically in an android program? I need to pull some API information (for example battery state, battery percentage, android os version) and would like to save it a R.string value. I know how to read it:

     String helloValue= getResources().getString(R.string.hello);
    

    I've also looked at: Change value of R.string programically? but it seems that only involves changing language and he ended up doing it a different way. Can anyone lend a hand please? I've also looked here: http://developer.android.com/guide/topics/resources/string-resource.html and found nothing to help out either :(