简体   繁体   中英

How set image into ImageView using Glide and a URI?

I'm trying to display an image in a ImageView using Glide library, the image is in res > drawable folder, and its name retrived from a db. How can I get a resource using an Uri?, redWifi.getImagen() returns a string like "imagename.png".

I'm using the next code but doesn't show the image.

Glide.with(detallesRedGuardadaActivity.this)
                .load(Uri.parse("file:///android_asset/" + redWifi.getImagen()))
                .asBitmap()
                .into(iconoRed);

I tried with .load(Uri.parse("file://android_asset/" + redWifi.getImagen())) but still not working.

The URL file:///android_asset/ means that you are pointing to assets folder in your project. If you don't know where to put this directory, take a look at the Project structure with Gradle here .

After that put your images in that folder, and then this should work:

Glide.with(context)
    .load(Uri.parse("file:///android_asset/"+fileName))
    .into(imageView);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM