Android-Universal-Image-Loader does not save uploaded images when scrolling in gridview

I am using the Android-Universal-Image-Loader library to upload deleted images to ImageView in GridView cells.

Here's the imageLoader configuration:

new ImageLoaderConfiguration.Builder(Config.context) .threadPriority(Thread.NORM_PRIORITY - 2) .memoryCacheSize(20 * 1024 * 1024) // 20 Mb .memoryCache(new LruMemoryCache(20 * 1024 * 1024)) .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) .tasksProcessingOrder(QueueProcessingType.LIFO) .enableLogging() // Not necessary in common .build(); 

and display options:

 new DisplayImageOptions.Builder() .showStubImage(R.drawable.blank) .showImageForEmptyUri(R.drawable.no_image) .build(); 

Problems: When activity starts with gridview, everything works correctly, and the images appear in the cells, then I scroll down the grid (I have about 20 elements in the grid), and other images load properly. But as soon as I scroll up, images that have already downloaded will start to load again.

After several scrolls up and down, the grid saves all the images and they no longer disappear.

Someone has encountered similar problems, or you know what I did wrong. Thanks for the help.

ADDED : Here is the getView method in my adapter:

 @Override public View getView(final int position, View convertView, ViewGroup parent) { View view = convertView; ViewHolder holder; if ( view == null ) { view = Config.context.getLayoutInflater().inflate(R.layout.featured, null); holder = new ViewHolder(); holder.titleText = (TextView) view.findViewById(R.id.featured_title); holder.priceText = (TextView) view.findViewById(R.id.featured_price); holder.image = (ImageView) view.findViewById(R.id.thumbnail_image); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } HashMap<String, String> listing = listings.get(position); /* set text values */ holder.titleText.setText(listing.get("title")); holder.priceText.setText(listing.get("price")); /* load image to list (AsyncTask) */ Utils.imageLoaderFeatured.displayImage(listing.get("photo"), holder.image, Utils.imageLoaderOptionsFeatured); return view; } 

PS. Let me know if you want to see another code (maybe a network adapter) to help me with this problem.

John

+8
android image universal-image-loader loader universal
source share
6 answers

I ran into the same problem in the Universal-Image-Loader Demo, and I hope the library developers will solve the problem in the next update.

UPDATE The problem is fixed using nostra13 , you need to update the library to version 1.9 and use this method of displaying images in imageView :

 ImageAware imageAware = new ImageViewAware(imageView, false); imageLoader.displayImage(imageUri, imageAware); 

He solved my problem. Some details why you should do this can be found here here and here.

+16
source share

you must use the Adapter and then implement the ViewHolder to make the flow scroll smooth and efficient. provide a tag for wrt images at their positions provided in getView() , and then there will be no problems.

+1
source share

Do not use the set tag in the getView () adapter. Always try to find view identifiers in the getview () method of the adapter.

 public View getView(final int position, View convertView, ViewGroup parent) { View view = convertView; ViewHolder holder; view = Config.context.getLayoutInflater().inflate(R.layout.featured, null); holder = new ViewHolder(); holder.titleText = (TextView) view.findViewById(R.id.featured_title); holder.priceText = (TextView) view.findViewById(R.id.featured_price); holder.image = (ImageView) view.findViewById(R.id.thumbnail_image); view.setTag(holder); HashMap<String, String> listing = listings.get(position); /* set text values */ holder.titleText.setText(listing.get("title")); holder.priceText.setText(listing.get("price")); /* load image to list (AsyncTask) */ Utils.imageLoaderFeatured.displayImage(listing.get("photo"), holder.image, Utils.imageLoaderOptionsFeatured); return view;} 
+1
source share

You must declare an instance of ImageLoader and DisplayImageOptions only once. Perhaps in the constructor.

 ImageLoader imageLoader = ImageLoader.getInstance(); DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true) .cacheOnDisc(true).resetViewBeforeLoading(true) .showImageForEmptyUri(fallbackImage) .showImageOnFail(fallbackImage) .showImageOnLoading(fallbackImage).build(); 
+1
source share

Same issue here using StaggeredGridView. Even with the memory cache and ImageAware method, it cannot be solved.

The only thing that worked for me was the cache extension from 4 to 10 MB. The list of images is small, but I have a very large image as a view title.

I noticed that imageViews are also updated by long click, is this even true for GridView?

In any case, the extension of the memory cache limit has also been fixed.

0
source share

.i also ran into the same issue and resolved the issue with wirting

Utils.imageLoaderFeatured.displayImage (listing.get ("photo"), holder.image, Utils.imageLoaderOptionsFeatured); .......

line inside if (view == null) ....... iewhen your converted view == null only then upload images and display.them .. this will solve your problem .....

-one
source share

All Articles