我正在使用Picasso在我的Android应用程序中显示图像:
/**
* load image.This is within a activity so this context is activity
*/
public void loadImage (){
Picasso picasso = Picasso.with(this);
picasso.setDebugging(true);
picasso.load(quiz.getImageUrl()).into(quizImage);
}
Run Code Online (Sandbox Code Playgroud)
我已启用调试,它始终显示红色和绿色.但从不显示黄色
现在,如果我下次加载相同的图像并且互联网不可用,则不会加载图像.
问题:
我正在使用Picasso下载各种图像.通常,我只是在显示这些,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, …Run Code Online (Sandbox Code Playgroud)