diff --git a/src/com/fedorvlasov/lazylist/ImageLoader.java b/src/com/fedorvlasov/lazylist/ImageLoader.java index 90af6b5..b941aa2 100644 --- a/src/com/fedorvlasov/lazylist/ImageLoader.java +++ b/src/com/fedorvlasov/lazylist/ImageLoader.java @@ -14,7 +14,7 @@ import java.util.WeakHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import android.app.Activity; +import android.os.Handler; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -25,7 +25,8 @@ public class ImageLoader { MemoryCache memoryCache=new MemoryCache(); FileCache fileCache; private Map imageViews=Collections.synchronizedMap(new WeakHashMap()); - ExecutorService executorService; + ExecutorService executorService; + Handler handler=new Handler();//handler to display images in UI thread public ImageLoader(Context context){ fileCache=new FileCache(context); @@ -147,8 +148,7 @@ public void run() { if(imageViewReused(photoToLoad)) return; BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad); - Activity a=(Activity)photoToLoad.imageView.getContext(); - a.runOnUiThread(bd); + handler.post(bd); }catch(Throwable th){ th.printStackTrace(); }