2011-12-10 38 views
3

我需要将数据对象放入包含softreferences的我的weakhashmap中。如何将我的“Drawable”对象转换为softreference?Java,将对象转换为softreference

WeakHashMap <String, SoftReference<Drawable>> tempPulled = new WeakHashMap<String,  SoftReference<Drawable>>(); 
Drawable pulled = BitmapDrawable.createFromResourceStream(null, null, conn.getInputStream(), "galleryImage", options); 
SoftReference<Drawable> sPulled;    
tempPulled.put(id, pulled); 

tempPulled应该把 “sPulled” 时,SoftReference的

回答

3

我认为这是你在找什么

SoftReference<Drawable> sPulled = new SoftReference<Drawable>(pulled);    

但你可能想添加一个队列中删除从地图SoftRefence应该引用的对象被删除(或缓存将钥匙成长,空softrefences。

0

Guava's MapMaker类,它允许你指定的软值看看。比自己重新实现更容易。

+0

我正在使用内置的类。不要重新发明任何东西 – CQM