使用ImageView
,我可以使用以下代码下载带回调的图像
Picasso.with(activity).load(url).into(imageView, new Callback()
{
@Override
public void onSuccess()
{
// do something
}
@Override
public void onError() { }
);
或者只是从这个Picasso.with(activity).load(url).get();
获取位图。无论如何都要添加回调才能下载图像?如果可能,请提供示例代码,干杯!
答案 0 :(得分:44)
您可以创建 Target
,然后修改目标回调方法Bitmap
中的onBitmapLoaded(...)
。方法如下:
// make sure to set Target as strong reference
private Target loadtarget;
public void loadBitmap(String url) {
if (loadtarget == null) loadtarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
// do something with the Bitmap
handleLoadedBitmap(bitmap);
}
@Override
public void onBitmapFailed() {
}
};
Picasso.with(this).load(url).into(loadtarget);
}
public void handleLoadedBitmap(Bitmap b) {
// do something here
}