0

How can I load an image using a URL that is saved in a database and display it in a Recycler View in an Image View

I have a database that displays data as an output in my app but I cant figure out how to make the URL for an image in the database load as an image.

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
  • Pretty unclear problem. What does it matter where you store your urls? If you need an image then get the url from the database and load image from url. Of course we assume that you know how to load an image from url. – blackapps May 26 '22 at 07:43

2 Answers2

2

you can load an image from URL by using Glide:

Import dependency

implementation 'com.github.bumptech.glide:glide:4.11.0'

        Glide
        .with(context)
        .load("URL placed here")
        .centerCrop()
        .placeholder(R.drawable.placeholder)
        .into(imageview)
Ammar Abdullah
  • 802
  • 4
  • 8
  • 21
  • I have a database with more than 1,500 URLs that correspond to their respective items in said database so placing over 1,500 URLs would be very time consuming and not very cost effective how would i go about using the column in the database that contains the URLs in this manner – Whoyoumecallit May 26 '22 at 05:09
  • @Whoyoumecallit for this you can use caching which is a feature of Glide. It will load the image once and then save their corresponding cache which will be used later. – Ammar Abdullah May 26 '22 at 05:13
0

There are multiple options available to load an image from URL.

You can use Picasso like this:

Picasso.get().load("your_url").into(imageView);

Also you can use Glide (Faster than Picasso)

Glide.with(this).load("your_url").into(imageView);

Or you can convert your URL to Bitmap and then set it into ImageView without using any library. See this for this approach: How to get bitmap from a url in android