Reputation: 713
How can I access the list of drawables under my project "res/drawables"? Im new to Android I've seen an example like this:
Field[] drawables = android.R.drawable.class.getFields();
for (Field f : drawables) {
try {
System.out.println("R.drawable." + f.getName());
} catch (Exception e) {
e.printStackTrace();
}
}
But this lists all the default drawables, not what I want:( I want to access those files and have their names to generate an xml, because my layout will be dynamic (number of drawables may differ from time to time).
Thanks for any help.
Upvotes: 0
Views: 1297
Reputation: 2374
One suggestion would be to follow a naming convention for all your drawables. Say prefix them with your app name 'app'.
for(Field f:drawables){
if(f.getName().startsWith("app")){
//Your drawable.
}
}
Upvotes: 0
Reputation: 8142
Replace
android.R.drawable.class.getFields();
with
your.application.package.R.drawable.class.getFields();
to access your drawables.
Upvotes: 1