在写APP时,想从.xml中获取@drawable/picname
Resources res = getResources();
int[] imageId = res.getIntArray(R.array.bookImage);
- 然后用Log.i监视值结果
07-09 21:34:34.809 11010-11010/com.three.learning I/image: 0
07-09 21:34:34.809 11010-11010/com.three.learning I/image: 0
07-09 21:34:34.809 11010-11010/com.three.learning I/image: 0
07-09 21:34:34.809 11010-11010/com.three.learning I/image: 0
07-09 21:34:34.809 11010-11010/com.three.learning I/image: 0
07-09 21:34:34.809 11010-11010/com.three.learning I/image: 0
最后,StackOverFlow 给出的答案是
TypedArray ar = context.getResources().obtainTypedArray(R.array.actions_images);
int len = ar.length();
int[] resIds = new int[len];
for (int i = 0; i < len; i++)
resIds[i] = ar.getResourceId(i, 0);
ar.recycle();