Problem loading Android list list

I have an application containing several lists. The list contains items consisting of images and text views.

All images have the size of thumbnails on the server, and the template used to upload them is as follows:

  • Creating a DrawableManager Image
  • in the getView () method, I do the following:

    • Pass thumb uri and ImageView instance to DrawableManagers getImageAsync method

    • First, the method will look on the SD card, if the image exists, if it boots from the SD card and saves softreference + update imageview drawable

    • If on sd does not exist. We select from HTTP and save to SD (if there is enough space), put it as a softreference and update the imageview drawable.

When the images on the SD card all work fine. But for the first time (or when using an application without an SD card), the images seem to fill in the wrong listviews lines when scrolling. When I stop scrolling, the problem is fixed automatically after a couple of seconds.

It almost looks like ImageView links are merged or something like that.

Any ideas?

I also include the getView method:

public View getView(int position, View convertView, ViewGroup parent) { ViewHolder vh; if (convertView == null) { convertView = inflater.inflate(R.layout.informationrow, null); vh = new ViewHolder(); vh.imageView = (ImageView) convertView.findViewById(R.id.rowInformationIcon); vh.textView = (TextView) convertView.findViewById(R.id.rowInformationTitleLine); convertView.setTag(vh); } else { vh = (ViewHolder) convertView.getTag(); } CustomCategory cc = items.get(position); if (cc != null) { vh.textView.setText(cc.get_name()); if (cc.getMediaUrl() != null) { _drawMgr.fetchDrawableOnThread(cc.getMediaUrl(), vh.imageView); vh.imageView.setBackgroundDrawable(getResources().getDrawable(R.drawable.imageframe)); } else { vh.imageView.setImageDrawable(getResources().getDrawable(R.drawable.trans4040)); vh.imageView.setBackgroundDrawable(null); } } return convertView; } 
+4
source share
2 answers

This is the view utility used by ListView ...

The convertView parameter passed to your getView() can refer to an existing element that has scrolled through the displayed part of the list and can be reused to display the element that now appears.

So yes, the same ImageView will be reused in multiple downloads in the code you posted. In your getView (), you should check if the download is loaded, and cancel it if it is no longer needed (or allow it to fill in the FIFO image cache somewhere, but not touch the ImageView, which is now needed for a later version, started download).

(An alternative, lazy implementation of developers, which involves infinite memory, is to ignore the convertView parameter and create new visual representations with every call. Don't do this. :)).

+1
source

Use this library to load images into a ListView. https://github.com/nostra13/Android-Universal-Image-Loader

+1
source

Source: https://habr.com/ru/post/1339463/


All Articles