Piotr Sagalara
Piotr Sagalara

Reputation: 2485

Get drawable from other resource folder

I've a project structure like that:

enter image description here

The folder "coffee_types" is an Android resource folder with type drawable created in the following way:

enter image description here

Previously, when I was using only main drawables folder, I was using this function to get the Drawable object:

private Drawable getDrawableByName(String name) {
    return getResources().getDrawable(getResources().getIdentifier(name, "drawable", getPackageName()));
}

I was trying to change it to make it work with the "coffee_types" folder with no success.

Any help appreciated.

Upvotes: 0

Views: 531

Answers (2)

AmirrezASe7eN
AmirrezASe7eN

Reputation: 35

It's not possible to access drawables from another directory.
But you could name the pictures like: "coffee_image_1", "coffee_image_2" etc. (like you did) and put them in the drawables folder.
It will be easier to find them this way.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006564

The folder "coffee_types" is an Android resource folder with type drawable

No, it is not. You cannot invent your own resource types.

Upvotes: 3

Related Questions