【发布时间】:2015-01-12 20:55:07
【问题描述】:
在res/drawable-mdpi 文件夹中,我有 26 个字母图像,分别命名为 big_0.png 到 big_25.png。
我想将它们全部添加(并忽略文件夹中的任何其他图像)到哈希映射:
private static HashMap<Character, Drawable> sHash =
new HashMap<Character, Drawable>();
最初我的计划是:
private static final CharacterIterator ABC =
new StringCharacterIterator("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
int i = 0;
for (char c = ABC.first();
c != CharacterIterator.DONE;
c = ABC.next(), i++) {
String fileName = "R.drawable.big_" + i;
Drawable image = context.getResources().getDrawable(fileName);
sHash.put(c, image);
}
但后来我意识到 R.drawable.big_0 到 R.drawable.big_25 的类型是 int 而不是 String。
所以请告诉我,如何正确遍历 26 张图像?
【问题讨论】:
标签: android android-resources getresource