Arty Arty - 3 years ago 145
Android Question

Get array of id drawable resources

I need many similar drawable resources.
I created the files necessary to me in the drawable folder
Then the file of resources with the array:

<array name="btn_style">

But when I write

int[] btn_draw = getResources().getIntArray(R.array.btn_style);

I receive zero from the array.

If I do

int[] btn_draw = {R.drawable.tile0,R.drawable.tile1};

All works fine.

Answer Source

If I understand your question.. here is your answer:

try this: You can use typed array..

<?xml version="1.0" encoding="utf-8"?>

        <string-array name="random_imgs">


Then in your activity access them like so:

TypedArray imgs = getResources().obtainTypedArray(R.array.random_imgs);
//get resourceid by index
imgs.getResourceId(i, -1)
// or set you ImageView's resource to the id
mImgView1.setImageResource(imgs.getResourceId(i, -1));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download