Android - How to get the names of pictures in drawable folder?

I´m creating a game for my college project and I was wondering if I can get the names(just the names) of the images I put inside the /drawable folder in android. It can also be the files I put inside the /raw folder, the option that works better.

Upvotes: 0

Views: 937

Answers (1)

Shrinithi
Shrinithi

Reputation: 336

Use the following snippet

Field[] ID_Fields = R.drawable.class.getFields();
     for (Field f : ID_Fields) {
        try {
            System.out.println(f.getName() + "sample");
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
     }

Upvotes: 1

Related Questions