创建资源ID的整数数组整数、数组、资源、ID

2023-09-04 23:49:10 作者:狗比人忠ら

我有一些照片在我的RES /绘制文件夹。比方说img1.png, img2.png和img3.png

我目前正在创建这些图像的ID int数组的Java像 这种

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

相反,是有可能的资源之一来创建一个int ARR /值的文件 (说的strings.xml)这样

 <整型数组名=img_id_arr>
       <项目> @可绘制/ IMG1< /项目>
       <项目> @可绘制/ IMG2< /项目>
       <项目> @可绘制/ IMG3< /项目>
   < /整数数组>
 

,然后通过

访问它在Java中

  getResources()。getIntArray(R.array.ing_id_arr)
 
C语言.由键盘输入10个整数存入数组a中,再任意输入一个整数k,然后在数组中查找k出现的次数

解决方案

使用只是阵列,而不是整数数组。请参见类型数组的开发指南。

I have some images in my res/drawable folder. Let's say img1.png, img2.png and img3.png

I am currently creating an int 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 int arr 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.ing_id_arr)

解决方案

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

 
精彩推荐
图片推荐