zomry1 zomry1 - 3 months ago 16
Android Question

Change int from xml Resource

I am new in Android Studio and i like the idea of having a resources files so I open a resource file (xml) in the name of integers and i put this code in him:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="omry">1</integer>
</resources>


and my code that get the var is:

Integer zomry101 = new Integer(this.getResources().getInteger(R.integer.omry));


and now i want do that if i click on a button it will add 1 to the omry int in the file, I know how to do the click event but I dont know how to change the xml file.
please help.

Answer

First thing's first Resources CAN NOT be Changed or Modified once an apk has been built. You can only add values to resources that need not to be modified.

So what to do? Preferences allow you to save and modify values at run time. This SO explains how to use Shared Preferences in your app.

Have a look at this for easy to use Utility for Shared Preferences.

Comments