Skip to content

Commit

Permalink
Use handler to display images in UI thread. This way we don't depend …
Browse files Browse the repository at this point in the history
…on Activity context. Fixes problems with fragments.
  • Loading branch information
thest1 committed Dec 6, 2012
1 parent b41084d commit 232d7f6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/com/fedorvlasov/lazylist/ImageLoader.java
Expand Up @@ -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;
Expand All @@ -25,7 +25,8 @@ public class ImageLoader {
MemoryCache memoryCache=new MemoryCache();
FileCache fileCache;
private Map<ImageView, String> imageViews=Collections.synchronizedMap(new WeakHashMap<ImageView, String>());
ExecutorService executorService;
ExecutorService executorService;
Handler handler=new Handler();//handler to display images in UI thread

public ImageLoader(Context context){
fileCache=new FileCache(context);
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 232d7f6

Please sign in to comment.