3

ソフトリファレンスを含むweakhashmapにデータオブジェクトを配置する必要があります。「Drawable」オブジェクトをソフトリファレンスに変換するにはどうすればよいですか?

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」を配置する必要があります

4

2 に答える 2

3

これがあなたが探しているものだと思います

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

ただし、参照されているオブジェクトが削除された場合は、キューを追加してマップからSoftRefenceを削除することをお勧めします(または、キャッシュがキーと空のsoftrefenceで大きくなります。

于 2011-12-10T21:40:44.567 に答える
0

ソフト値を指定できるGuavaのMapMakerクラスを見てください。自分で再実装するよりもはるかに簡単です。

于 2011-12-10T21:38:43.553 に答える