Android Define integer array


Example

In order to define an integer array write in a resources file

res/values/filename.xml

<integer-array name="integer_array_name">
    <item>integer_value</item>
    <item>@integer/integer_id</item>
</integer-array>

for example

res/values/arrays.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer-array name="fibo">
        <item>@integer/zero</item>
        <item>@integer/one</item>
        <item>@integer/one</item>
        <item>@integer/two</item>
        <item>@integer/three</item>
        <item>@integer/five</item>
    </integer-array>
</resources>

and use it from java like

int[] values = getResources().getIntArray(R.array.fibo);
Log.i("TAG",Arrays.toString(values)));

Output

I/TAG: [0, 1, 1, 2, 3, 5]