在Android应用程序中使用Picasso下载图像时出错

时间:2015-04-18 18:56:38

标签: android picasso

我正在使用Picasso在我的Android应用程序中下载图像。但由于某些原因,我的代码总是只下载第一张图片。

这是我的代码:

public void setAddresses(String addressesAsString) {
    String[] addresses = addressesAsString.split("\n");
    addresses[0] = "http://perec.info/wp-content/uploads/perecinfo-panda-1.jpg";
    addresses[1] = "http://bessarabiainform.com/wp-content/uploads/2014/10/dinamo_kiev_1680x1050_5693-300x187.jpg";
    uris = new Uri[addresses.length];
    for (int i = 0; i < addresses.length; ++i) {
        uris[i] = Uri.parse(addresses[i]);
    }
}

public void downloadAllImages() {
    totalDownloaded = 0;
    for (Uri uri: uris) {
        Target target = new Target() {

            @Override
            public void onPrepareLoad(Drawable arg0) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onBitmapLoaded(Bitmap arg0, LoadedFrom arg1) {
                // TODO Auto-generated method stub
                processDownloadedImage();
            }

            @Override
            public void onBitmapFailed(Drawable arg0) {
                // TODO Auto-generated method stub
                processDownloadedImage();
            }

            void processDownloadedImage() {
                totalDownloaded++;
                Log.i("Downloaded", "" + totalDownloaded);
                if (totalDownloaded == uris.length) {
                    context.onDownloadingComplete();
                }
            }
        };
        Picasso.with(context).load(uri).resize(50, 50).into(target);
    }
}

任何想法为什么会发生这种情况?

0 个答案:

没有答案