ImageLoader 线程池 单例 使用模板
2015-06-30 00:25
302 查看
ImageLoader 线程池 单例 使用模板
package com.cggame.trillion;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import android.graphics.Bitmap;import android.widget.ImageView;public class ImageLoader {private static ImageLoader imageLoader;private ExecutorService pool = null;private static final int MAX_THREAD_COUNT = 5;private ImageLoader() {imageLoader = new ImageLoader();pool = Executors.newFixedThreadPool(MAX_THREAD_COUNT);}public static void loadImageAsync(final ImageView imageView, final String path) {if (imageLoader == null) {imageLoader = new ImageLoader();}imageLoader.pool.execute(new DownLoadThread(imageView, path));}private static void downloadImage(final ImageView imageView, String path) {final Bitmap bitmap = null;// 开始下载// bitmap = ...;// 下载完成imageView.post(new Runnable() {@Overridepublic void run() {imageView.setImageBitmap(bitmap);}});}private static class DownLoadThread extends Thread {private ImageView imageView;private String path;public DownLoadThread(ImageView imageView, String path) {this.imageView = imageView;this.path = path;}@Overridepublic void run() {super.run();downloadImage(imageView, path);}}}
相关文章推荐
- LeetCode Simplify Path
- 2015年6月29日 课设日志
- win7-时间更新
- 2015062910 - 一周搞定Effective java
- android searchView加ListView共同使用
- mysql定时器
- 定义一个功能,记录程序运行的次数。满足5次后,给出提示,试用次数已到,请注册
- 输入框只能输入数字 以及其他限制的总结
- AFNetworking获取服务端plist文件,XML文件
- POJ 3592 强连通缩点+spfa最长路
- 公安项目项目感想
- 注解开发spring-aop 入门
- 2015062909 - 黑鹰坠落
- .Net 自定义事件
- .Net 自定义事件
- 第八十八天 how can I 坚持 angelaJs
- 三范式
- 37条常用Shell命令
- virtualtree 的使用(Delphi)
- 2015062908 - EffactiveJava笔记 - 第46条 foreach优先传统for循环(4)