Good day.

There is a path to the picture, which is recorded in the String. The picture is stored somewhere on the Internet.

You need to make Drawable, which will contain this image, so that later it can be thrown into the ImageView.

Is it possible to do this?

  • But is it not easier to keep the line, and how will it be necessary, then upload the image to imageview? What is the need to drawable? - Android Android

1 answer 1

You need one of the libraries for downloading, caching, and displaying pictures from the network. For example, UIL or Picasso

In the first case, the code will be as follows:

ImageLoader imageLoader = ImageLoader.getInstance(); // Get singleton instance imageLoader.displayImage(imageUri, imageView); 

In the second so:

 Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView); 

Write your bike is not worth it. Moreover, UIL has a download listener, which comes with a Bitmap, which can be simply converted into Drawable, if you really need it. Although, most likely, you do not need it.

  • I have a RecyclerView here that contains a grid from ImageView. Do not tell me exactly where it is worth using Picasso, in particular, the code that you gave above? In the onBindViewHolder adapter, or in the ViewHolder? - Crok
  • one
    @Crok, there are different opinions on this. Personally, I like more onBindViewHolder. And UIL instead of Picasso. But I can't tell you exactly what the difference is. Will work in any combination. - Yuriy SPb