Hi im using Glide to load image from my drawable folder and all works fine, this is my code :
Glide.with(this).load(R.drawable.my_drawable_image_name).into(myImageView);
i'm wondering if there is a way to load the image just by name , something like :
Glide.with(this).load(my_drawable_image_name).into(myImageView);
because i want to get the image name dynamically ,for example from a database...
do you have any suggestion about that? thanks in advance.
into(myImageView); Load method of Glide also accept drawable object as a parameter to load image. You just have to get the drawable object from your drawable image and pass it to the load method.
Before getting into Glide example, we should know what is glide, Glide is an image processing library developed by muyangmin. Using glide library we can show image, decode images,cache images, animated gifs and many more. This example demonstrate about how to integrate glide in android.
Using glide library we can show image, decode images,cache images, animated gifs and many more. This example demonstrate about how to integrate glide in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.
Many of us use glide for image loading but only some of us know its real power. If we dive into the features of glide, the article will go into TL;DR category.
You can read some comparison here and here. Glide offers some additional advantages over other image loading libraries. For example, when loading an image, Glide will cache both a version of the image in its original size as well as one that’s the size of its intended ImageView.
Call getImage
method for get Drawable
using Name only.
Glide.with(this).load(getImage(my_drawable_image_name)).into(myImageView); public int getImage(String imageName) { int drawableResourceId = this.getResources().getIdentifier(imageName, "drawable", this.getPackageName()); return drawableResourceId; }
Try this:
Glide.with(this) .load(getResources() .getIdentifier("my_drawable_image_name", "drawable", this.getPackageName()) .into(myImageView);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With