Neaf Plays Neaf Plays - 7 months ago 28
Android Question

How can I set a String variable on R.drawable with glide?

I'm using the glide Library to load images and I made a method that goes like this:

void alterarInformacoes(ImageView slotImagem, String image) {

But it doesn't work, I'd like to know if there's a way to use a string with the name of the drawable so that I can use a function to dynamically set the images.

Answer Source

You can get int value of drawable resource by name with this code:

int drawableResourceId = this.getResources().getIdentifier("nameOfDrawable", "drawable", this.getPackageName());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download