Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Glide to download image to load into a TextView?

In my app I download an image from an URL and set it into an ImageView through Glide, however, I'm trying to remove a few unnecessary layouts, so is it possible to use Glide to download an image and set into to TextView?

try {
  Glide.with(holder.logo.getContext())
       .load(standingObjectItems.get(position).getImgId()).diskCacheStrategy(DiskCacheStrategy.ALL)
       .error(R.mipmap.ic_launcher)
       .placeholder(R.mipmap.ic_launcher)
       .into(holder.logo);

} catch (IllegalArgumentException | IndexOutOfBoundsException e) {
  e.printStackTrace();
}
like image 575
RedEagle Avatar asked Nov 08 '15 13:11

RedEagle


People also ask

How do you download pictures from Glide?

To simply load an image to LinearLayout, we call the with() method of Glide class and pass the context, then we call the load() method, which contains the URL of the image to be downloaded and finally we call the into() method to display the downloaded image on our ImageView.

Why we use Glide in android?

Glide is an Image Loader Library for Android developed by bumptech and is a library that is recommended by Google. It has been used in many Google open source projects including Google I/O 2014 official application. It provides animated GIF support and handles image loading/caching.


1 Answers

Here is a simple example of how to do using Kotlin.

GlideApp.with(context)
            .load("url")
            .placeholder(R.drawable.your_placeholder)
            .error(R.drawable.your_error_image)
            .into(object : CustomTarget<Drawable>(100, 100) {
                override fun onLoadCleared(drawable: Drawable?) {
                    header.companyLogoJob.setCompoundDrawablesWithIntrinsicBounds(drawable,null,null,null)
                }

                override fun onResourceReady(res: Drawable, transition: com.bumptech.glide.request.transition.Transition<in Drawable>?) {
                    header.companyLogoJob.setCompoundDrawablesWithIntrinsicBounds(res,null,null,null)
                }

            })
like image 84
groff07 Avatar answered Oct 19 '22 17:10

groff07