如何显示资源可绘制列表列表、资源

由网友(好好过生活丶)分享简介:我想显示所有资源可绘制在一个列表,以便用户可以选择之一。有没有什么办法可以遍历所有R.drawable项目,所以我没有到c他们难以$ C $到我的程序?I would like to display all resource drawables in a list so that the user can selec...

我想显示所有资源可绘制在一个列表,以便用户可以选择之一。有没有什么办法可以遍历所有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();
    }
}

参考:http://www.darshancomputing.com/android/1.5-drawables.html

阅读全文

相关推荐

最新文章