zomry1 zomry1 - 1 year ago 129
Java Question

Change int from xml Resource (Android Studio)

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"?>
<integer name="omry">1</integer>

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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download