I have an issue : in getView() function of ArrayAdapter, I execute loading image to ImageView with AsyncTask. But when this item is invisible(scroll listview), AsyncTask function still loading image. I want to disable AsyncTask process if item is invisible. Have a solution for this issues?
This would involve two steps.
1) Realize that the item view has scrolled out of the screen (or will no longer be used for another reason).
You can set use setRecyclerListener()
to add a RecyclerListener
object that will be notified whenever an item view is about to be recycled (onMovedToScrapHeap()
).
2) Actually abort the AsyncTask.
It depends on what you're actually doing inside. If doing an HTTP request (as it seems from the description) then calling cancel(true)
should cause an interrupt and abort the download.
However, before all this, consider: if the image was being downloaded and you interrupt this process, it means that it will probably have to be downloaded again when you scroll back up. Perhaps a better strategy would simply be to let the download complete, but not load the ImageView
itself it it has been reused (which you can detect by setting a tag on it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With