How to get Integer value from res/integers.xml? How to get Integer value from res/integers.xml? android android

How to get Integer value from res/integers.xml?


It should be done like this:

Resources res = getResources();int i= res.getInteger(R.integer.int_value);

where int_value is the variable name given in your xml


You're looking at the android.R.integer instead of your.namespace.R.integer.

Eclipse probably imported the wrong one; it does that sometimes, it's rather annoying.

Go to your imports at the top of the file and remove:import android.R;

Then you should be able to use the quick-fix to add the correct import.


May be you have to clean your project once before accessing these file. I do it like this and it always works.

Resources r = getResources();int i = r.getInteger(R.integer.<variable_name>)

Try to clean your project and restart your eclipse because this is the right way of doing it.