<!-- 以为这样,但是不行的 --> <integer-array name="items_id"> <item>@drawable/qwe</item> <item>@drawable/qwe1</item> </integer-array> <!-- 要这样定义 --> <string-array name="items_id"> <item>@drawable/qwe</item> <item>@drawable/qwe1</item> </string-array>
// 代码中获取,其他资源也是一样的方法 TypedArray ar = context.getResources().obtainTypedArray( R.array.items_id); int len = ar.length(); int[] resIds = new int[len]; for (int i = 0; i < len; i++){ resIds[i] = ar.getResourceId(i,0); } ar.recycle();