1

I'm new to android, I want to know how to load an image from URL in Recycler view and easy definition of what is the use of Bitmap and their functions while loading the image from URL. I don't want to use any third party library. Kindly provide the solution for this.

Shree Krishna
  • 8,474
  • 6
  • 40
  • 68
Sayyaf
  • 316
  • 1
  • 4
  • 12
  • 1
    Why you don't want to use any third party library? – thealeksandr Oct 29 '15 at 06:50
  • use volley NetworkImageView – Prashant Mishra Oct 29 '15 at 06:54
  • You could check this question: http://stackoverflow.com/questions/8992964/android-load-from-url-to-bitmap But I would suggest use third party library like Picasso or Fresco. – quangson91 Oct 29 '15 at 06:55
  • http://developer.android.com/intl/zh-tw/training/volley/request.html – Prashant Mishra Oct 29 '15 at 06:57
  • Check this Link, It will help you. [How to load an ImageView by URL in Android?](http://stackoverflow.com/questions/2471935/how-to-load-an-imageview-by-url-in-android) If you need third party library, I my suggestion is [Android-Universal-Image-Loader](https://github.com/nostra13/Android-Universal-Image-Loader). – SeongjunKang Oct 29 '15 at 07:00
  • Why not use third party libraries? They're easy to use and built by amazing developers and thoroughly tested by a large community, not to mention they have a lot of functionality! Here's your best bet for an image loading a caching library http://square.github.io/picasso/ – SniperDW Oct 29 '15 at 06:50
  • Thanks for the suggestion but my task is not to use the Third Party Libraries. that is the issue. more over I'm unlikely finding difficulty to use the Url and Display in Recycler View. – Sayyaf Oct 29 '15 at 09:00

4 Answers4

2

Your question seems a bit unclear Either you are asking for reading the image with URL or anything else. If so you can Read Image and set It to your ImageView like this way

InputStream in = (InputStream) new URL(imageUrl).getContent(); //Reads whatever content found with the given URL Asynchronously And returns.
                Bitmap bitmap = BitmapFactory.decodeStream(in); //Decodes the stream returned from getContent and converts It into a Bitmap Format
                yourImageView.setBitmap(bitmap); //Sets the Bitmap to ImageView
                in.close(); //Closes the InputStream

Where imageUrl is a complete URL which points to your Image like something.com/image1.jpg

Shree Krishna
  • 8,474
  • 6
  • 40
  • 68
  • Yeah the first thing is to read and later I want to display multiple Url images in a Recycler view. And can u please explain the concept of Bitmap. – Sayyaf Oct 29 '15 at 09:02
  • Ok I have added some comments for clearance of codes. Bitmap is a class that represents the Images and specific type of Drawable. You can have a look at Bitmap Doc For Details. http://developer.android.com/reference/android/graphics/Bitmap.html – Shree Krishna Oct 29 '15 at 09:10
  • Can you provide an sample program for it, so it would help me understand more precisely? – Sayyaf Oct 29 '15 at 09:12
  • Create an application yourself. Put an ImageView in xml. And Copy the code I've given and paste. Replace imageUrl with this URL for Sample https://www.gstatic.com/webp/gallery3/1.png Your ImageView will show the Image from URL. *Note : yourImageView mean that is your imageview. And don't forget to prefix url with https://* – Shree Krishna Oct 29 '15 at 09:19
1

I think u already have string URL. Refer this link bitmap link here this method can be declared inside the onBindViewHolder().

Community
  • 1
  • 1
rafeek
  • 103
  • 1
  • 4
  • 13
0

As they all said you should use a Third part library. You can chose them here https://android-arsenal.com/

I would recommend Glide : http://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en

Laurent Russier
  • 658
  • 5
  • 24
0

I found the answer to my problem, I used Asynctask to Load multiple URL to load image from url, without using thrid party libarires. Where the downloading takes place in the Background thread. This reduces the work on the main UI thread and downloading runs parallely on the background thread and the result of the bitmap is passed on the onPostExecute() method.which can be finally passed on the OnBindViewHolder to bind the image to its respective view.

Sayyaf
  • 316
  • 1
  • 4
  • 12