如何显示资源可绘制列表 [英] How to display list of resource drawables
本文介绍了如何显示资源可绘制列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示所有资源可绘制在一个列表,以便用户可以选择之一。有没有什么办法可以遍历所有R.drawable项目,所以我没有到c他们难以$ C $到我的程序?
I would like to display all resource drawables in a list so that the user can select one. Is there any way to loop through all R.drawable items so I don't have to hard code them into my program?
推荐答案
在绘制类使用getFields方法,您可以遍历可绘制的完整列表。
Using the getFields method on the drawable class, you are able to iterate through the entire list of drawables.
Field[] drawables = android.R.drawable.class.getFields();
for (Field f : drawables) {
try {
System.out.println("R.drawable." + f.getName());
} catch (Exception e) {
e.printStackTrace();
}
}
参考:<一href="http://www.darshancomputing.com/android/1.5-drawables.html">http://www.darshancomputing.com/android/1.5-drawables.html
这篇关于如何显示资源可绘制列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文