<resources> <!-- Tracks Information --> <array name="music_ids"> <item>@raw/sf_the_typewriter</item> <item>@raw/sf_facades</item> <item>@raw/sf_ah_vous_dirai_je_maman_k265</item> <item>@raw/sf_jesu_meine_freude_bwv227_weicht_ihr_trauergeister</item> <item>@raw/sf_music_of_the_spheres</item> <item>@raw/sf_cosi_fan_tutte_k588_act_1_scene_2_terzettino_soave_sia_il_vento</item> <item>@raw/sf_ah_vous_dirai_je_maman_k265</item> <item>@raw/sf_clair_de_lune</item> <item>@raw/sf_mongol_gerin_magtaal</item> <item>@raw/sf_der_freischutz_opera_j277_act_3scene_6_jagerchor_was_gleicht_wohl_auf_erden</item> </array> </resources>
这些资源文件保存在了资源数组里,res/values/arrays.xml
取出:
TypedArray array = getResources().obtainTypedArray(R.array.music_ids); int length = array.length(); int[] resIds = new int[length]; for (int i = 0; i < length; i++) { resIds[i] = array.getResourceId(i, 0); } array.recycle();