Load images one by one in RecyclerView - android

I am having a uniquecode text in my recyclerview list item and by using that i have to call an API and get image URL and load it in the appropriate list item.
I am using retrofit for getting the image url form API.
I am calling the retrofit on onBindViewHolder of adapter in recyclerview.
In my android log i can see the response of retrofit and for the first 6 list item of recyclerview i am getting correct image and for the next list items the same 6 images are repeating. Anyone got this type of issue.
Please help me to overcome this.
Thanks.

In your implementation, You are making Two Network Call in onBindViewHolder, one for getting the image URL using the uniquecode text and another one for Loading The Url, the first one is not very useful unless the image url change while you scroll the RecyclerView(i guess not),
Another approach would be to first, fetch the image Url and put that Url in your item(list) for the RecyclerView and then only load the image Url in your RecyclerView Adapter

You should fetch your picture links outside ViewHolder in to a list, and use pagination or something similar for downloading more items when scrolled.

Related

How to add text content first time from first API and add Images from second API in same recyclerview^

I want to show list with images and text .But problem is, data is huge when i fetch image and text in one API , it takes too much time too load. So i want to show text first from first API and show in recyclerview,which i can do. But, how to add images after that in same recyclerview, which i was calling from second API.
Your Adapter should hold both text and image per entry.
Upon text received, you load and update the RecyclerView as you do, and since the image field is null, you hide or show a placeholder image.
Once the real image is ready, you update the datasource and notifyItemChange, so that the cell is re-binded and you can show the image.
However I would strongly suggest to keep the model hold meta data (ie. String text and URL image) and use Fresco or Picasso to handle the image loading.

Variable number of image buttons

basically what am doing is am querying some data from firebase and inside these data is a URL for an image of a specific item. Now since its a query i could get different result form the firebase where i can get 4 images or sometime maybe 1 image.
And i want to display the images in a grid layout ( similar to that of Instagram posts) where the user can click on an image and it shows the user some details about that item. This is the part where am stuck at.. i dont know how to do it since i have a variable number of images.
if there is a way, please help
you can use the Recyclerview and provide the model with those details. It will automatically create those many rows in list.
Here you can follow this to do this.

Loading image after second Volley JSON request into a RecyclerView using Picasso?

I am making use of the Soundcloud API and displaying the search results into a RecyclerView that I have created. In my RecyclerView, each element is inside of a cardView, which contains a textView, for the title of the search result, and an imageView, for the image/album art of the result. The way that the Soundcloud API works is that when you are searching for something, it will provide you with the track IDs, titles, and other information for all of the search results. But, it does not include the album art URLs in the search result response. In order to get the album art for the search results, I must create separate JSON requests for each of the search results that I get back from the primary JSON request using the track IDs. I am perplexed on how and when to request the secondary JSONs via Volley.
Currently, I am issuing the secondary requests with the onBindViewHolder method of my RecyclerView Adapter class. This does work, but one minor problem that is present with this implementation is that when I scroll down a couple results on the screen and immediately scroll back up, some of the images get misplaced and are put into the wrong elements and the proper images take a couple seconds to load back in. This happens because the images are recycled and the onBindViewHolder method is only called when an element of the RecyclerView needs to be rendered or re-rendered. So, does anyone have a solution as to when I could make the secondary JSON requests for the album art?
You could use a ListView rather than a RecyclerView. That way your cells aren't recycled, and you don't have to worry about each cell being destroyed. The trade off is that you don't have the performance of the RecyclerView, but it might be worth it in this case.

To Reuse images and text in list view when internet is not available

I have created five Horizontal ListView with images and texts in one activity. Using Lazy loading of images concept it is working fine. Now when it is offline, the list is showing blank,ie., no data . I need to implement memory-caching concept, such that when it is offline it will be showing the previous session datas(images & texts).
In oncreate: I am calling the Asynctask. In doinbackground method of asynctask,I am consuming Webservices containing images & texts,then I am passing those datas to the adapter. And in postexecute, I am setting my adapter to Listview.
In adapter class: getview method I am setting the texts and loading the images using lazy loading.
Please help me to get rid of this. Thanks in advance
You should store text etc. in an SQLiteDatabase and store your Images on external storage.

gridview load remote image . updating view?

I am using a GridView having image as child items.
The getView functions loads a default image from the application "Loading.gif" for all the child items.
In another thread I load all the images to some Bitmap type into the adapter.
Is it wise enough to call adapter.notifyDataSetChanged() after each image is loaded ?
Or is there and alternative way to directly update the image ?
Checkout the technique used in ListView , where default image used in listview items. And a thread load images for list items and update the new images without adapter.notifyDataSetChanged() called.
http://iamvijayakumar.blogspot.com/2011/06/android-lazy-image-loader-example.html
If you want more efficient way to do this then check this out.
http://developer.android.com/resources/samples/XmlAdapters/src/com/example/android/xmladapters/ImageDownloader.html

Categories

Resources