1

I am using ImageLoader in order to load images to a ListView.

This is the code I am using to load the image:

ImageLoader.getInstance().displayImage(url, holder.image, options, animateFirstListener);

When the app is loaded the table is shown well, but the images are not loaded. If I scroll the table down and then up images are loaded properly. All other images are loaded properly. Only the first images presented when the app runs are not loaded for some reason. The rest of the cell data is filled OK.

I added to the listener: AnimateFirstDisplayListener the "onLoadingFailed" method in order to try and understand the problem. It returns the fail error: DECODING_ERROR.

Does anyone know what am I missing?

OK. I think I got it. I use this line to build the URL:

String url = "http://www.domain.com/getImage?newsId=" + feedItem.getId() + "&w=" +
                    holder.image.getWidth() + "&h=" + holder.image.getHeight(); 

The method: holder.image.getWith() (and getHeight) returns "0" on the initial load. Does anyone has a clue why is it?

bashan
  • 3,572
  • 6
  • 41
  • 58
  • Can you verify if the URLs are valid image urls by printing them before giving to the loader? – Sharjeel Jul 31 '15 at 20:35
  • They are valid. As I wrote: when I simply scroll down and then up all images loaded properly. – bashan Jul 31 '15 at 20:39
  • I think the problem lies with this listener animateFirstListener. – Riyaz Ahamed Jul 31 '15 at 20:46
  • how do you define ImageView in your xml? If it's wrap_content then at first it will give 0 since there no image is set and it's empty. – Sharjeel Jul 31 '15 at 20:58
  • Also, it will always give 0 if you try to get width in onCreate. Here's the correct way to getWidth of ImageView http://stackoverflow.com/questions/4680499/how-to-get-the-width-and-height-of-an-android-widget-imageview – Sharjeel Jul 31 '15 at 21:02
  • Thanks @Sharj, In this solution I should add a listener that will return the size when available. But right after that code I should load my image. What will happen if the event will not be triggered but the image will be loaded? How I be sure that the width and height are available for me? – bashan Aug 01 '15 at 07:18

1 Answers1

0

The reason for this issue happened because the methods:

holder.image.getWidth()
holder.image.getHeight()

returned: 0. This probably happened since Android didn't have the size yet. The solution I used came from @Sharj's url.

bashan
  • 3,572
  • 6
  • 41
  • 58