Using ImageLoader with ListView on Android

时间:2015-07-31 20:30:33

标签: android listview universal-image-loader

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?

1 个答案:

答案 0 :(得分:0)

出现此问题的原因是因为方法:

string x = "Mark";
string y = "John";

// Added Pipes to show the spaces provided by the composite format string
Console.WriteLine("|{0,-5}| : |{1,7}|", x, y);

返回:0。 这可能发生,因为Android还没有尺寸。 我使用的解决方案来自@ Sharj的网址。