我正在使用毕加索下载各种图像。通常,我只是在ImageView
中显示这些内容,但在这种情况下,我希望对它们进行强有力的参考,以便我可以在不同的地方使用它们,而无需返回缓存或重新下载它们。这里是我在尝试做(注意,有更多这一类 - 我只是把范围缩小到有关这个问题的部分):毕加索将图像加载到目标中
public class MapLayer {
private Context mContext;
private String mType;
private Drawable mIcon = null;
public MapLayer (Context context, String type) {
mContext = context;
mType = type;
downloadIcon();
}
public Drawable getIcon() {return mIcon;}
private void downloadIcon() {
String url = mContext.getString(R.string.maps_icon_url).replace("${type}", mType));
Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Log.d(TAG, "on bitmap loaded");
mIcon = new BitmapDrawable(mContext.getResources(), bitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
Log.d(TAG, "on bitmap failed");
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
Log.d(TAG, "on prepare load");
mIcon = placeHolderDrawable;
}
};
ImageDownloader.getSharedInstance().load(url).into(target);
}
}
在任何情况下,我得到输出:
on prepare load
,但没有别的。我的图标始终为空。我从其他职业我知道这个,我叫getIcon()
。
我在这里错过了什么?谢谢你的帮助。
这就是我需要做的。非常感谢! – Alex