Android编程学习之异步加载图片的方法

2019-12-10 19:58:56于海丽
  • for (File f : files)   f.delete();  
  • }   }  

    (2)、缓存到手机内存的实体类:

     

     
    1. package net.loonggg.util;   import java.lang.ref.SoftReference;  
    2. import java.util.HashMap;   import android.graphics.Bitmap;  
    3. public class MemoryCache {   private HashMap<String, SoftReference<Bitmap>> cache=new HashMap<String, SoftReference<Bitmap>>();  
    4. public Bitmap get(String id){   if(!cache.containsKey(id))  
    5. return null;   SoftReference<Bitmap> ref=cache.get(id);  
    6. return ref.get();   }  
    7. public void put(String id, Bitmap bitmap){   cache.put(id, new SoftReference<Bitmap>(bitmap));  
    8. }   public void clear() {  
    9. cache.clear();   }  
    10. }