Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display list of resource drawables [duplicate]

Tags:

android

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?

like image 744
Sparafusile Avatar asked Mar 29 '10 13:03

Sparafusile


1 Answers

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();
    }
}

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

like image 134
Seidr Avatar answered Nov 21 '22 09:11

Seidr