Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating integer array of resource IDs

I have some images in my res/drawable folder. Let's say img1.png, img2.png and img3.png. I am currently creating an integer array of these image IDs in Java like this

int[] imgIds = {R.drawable.img1, R.drawable.img2, R.drawable.img3}; 

Instead, is it possible to create an integer array in one of res/values files (say strings.xml) like this

<integer-array name="img_id_arr">     <item>@drawable/img1</item>     <item>@drawable/img2</item>     <item>@drawable/img3</item> </integer-array> 

and then access it in Java via getResources().getIntArray(R.array.img_id_arr)?

like image 601
android_stricken Avatar asked Mar 18 '11 01:03

android_stricken


1 Answers

Use just "array" instead of "integer-array". See Typed Array in the developer guide.

like image 117
resnbl Avatar answered Sep 24 '22 04:09

resnbl