I have found this example http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview/3068012#3068012 from Fedor which is absolutely great for what I need.
I have a question. if beside the Clear Cache button there would be a button with Cancel. How could I in onClick cancel the image download thread from the UI ?
Thank you.
Edit: I think that it already has this method implemented:
public void stopThread()
{
photoLoaderThread.interrupt();
}
But I don't know how to access it from the UI Thread. In UI Thread I only do this:
adapter=new LazyAdapter(ctx, someString);
setListAdapter(adapter);
in LazyAdapter:
public View getView(int position, View convertView, ViewGroup parent) {
...
imageLoader.DisplayImage(imagePath, activity, holder.image);
return vi;
}
and in ImageLoader
public void DisplayImage(String url, Activity activity, ImageView imageView)
{
if(cache.containsKey(url))
imageView.setImageBitmap(cache.get(url));
else
{
queuePhoto(url, activity, imageView);
imageView.setImageResource(stub_id);
}
}
private void queuePhoto(String url, Activity activity, ImageView imageView)
{
//This ImageView may be used for other images before. So there may be some old tasks in the queue. We need to discard them.
photosQueue.Clean(imageView);
PhotoToLoad p=new PhotoToLoad(url, imageView);
synchronized(photosQueue.photosToLoad){
photosQueue.photosToLoad.push(p);
photosQueue.photosToLoad.notifyAll();
}
//start thread if it's not started yet
if(photoLoaderThread.getState()==Thread.State.NEW)
photoLoaderThread.start();
}
But I think an clear way is to download the sources from link text
Thank you for your help.