Change R.String Programmatically

Can you change R.string values ​​programmatically in an Android program? I need to pull out some API information (e.g. battery status, battery percentage, android os version) and would like to keep the value of R.string. I know how to read it:

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

I also looked at: Change the value of R.string programically? , but it seems that this is only due to a change in language, and in the end he did it differently. Can anyone lend a hand? I also looked here: http://developer.android.com/guide/topics/resources/string-resource.html and did not find anything to help: (

+6
android android-2.3-gingerbread
Mar 06 2018-12-12T00:
source share
4 answers

You cannot dynamically change strings.xml as this is a compiled resource. There are other mechanisms for saving data in Android, here is a good article that covers this topic: Data Warehouse . Hope this helps.

+11
Mar 06 2018-12-12T00:
source share

If you need to save a small amount of SharedPreferences information, you should use SharedPreferences , what exactly is it for :)

+2
Mar 06 2018-12-12T00:
source share

There are many ways to finish your ideas. But you cannot change your String resource (as well as R.java resource) or layout resource, ... and any other resource. You can do this by changing the resource to assets. it can read and write :)

0
Mar 06 2018-12-12T00:
source share

This way you can get the value from res / string.

 String str = getResources().getString(R.string.<name_of_value>); 

Now you can use this value of this variable (str) String.
But for me there is no way to set the value of res / string

0
Feb 17 '18 at 21:43
source share



All Articles