Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Following is my integers.xml file,

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="LOCATION_ALARM_INTERVAL">60000</integer>
    <integer name="MID_NIGHT_ALARM_INTERVAL">86400000</integer>
</resources>

if it was strings.xml, i could have access variable like below,

getString( R.string.<variable_name> );

but how can I do same to get value from integeres.xml file ?

when I write getResources().getInteger(R.integer. it is showing me 3 variable which I haven't declared.

enter image description here

So How can I access the variable which I declared in integers.xml file ?

like image 576
Vigbyor Avatar asked Oct 22 '13 04:10

Vigbyor


2 Answers

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

like image 98
Lavanya Avatar answered Oct 19 '22 13:10

Lavanya


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.

like image 29
Adam S Avatar answered Oct 19 '22 12:10

Adam S