Sophie
Sophie

Reputation: 2634

Show Progress while downloading image from server into imageview

I am ListView and would like to show progress, until image not downloaded from server into ImageView using Picasso library, still showing ic_launcher drawable while downloading image from server into ImageView, but what if i would like to show progress

    Picasso.with(context)
    .load(imageURL)
    .transform(transformation)
    .placeholder(R.drawable.ic_launcher)
    .error(R.drawable.ic_launcher)
    .into(viewHolder.imageView);

Upvotes: 3

Views: 3399

Answers (5)

Ashwin H
Ashwin H

Reputation: 723

mProgressDialog = new ProgressDialog(getActivity());
        mProgressDialog.setMessage("Wait a moment, loading image...");
        mProgressDialog.setCanceledOnTouchOutside(false);
        mProgressDialog.setCancelable(false);
        mProgressDialog.show();

        Picasso.with(getActivity()).load(mImagePath).into(mImageView, new Callback() {
            @Override
            public void onSuccess() {
                mProgressDialog.dismiss();
            }

            @Override
            public void onError() {
                mProgressDialog.dismiss();
                Toast.makeText(getActivity(), "Download failed", Toast.LENGTH_LONG).show();
            }
        });

Upvotes: 1

Thirumoorthy
Thirumoorthy

Reputation: 589

In the passed Google Developer Summit Thailand, Google introduced us an Image Loader Library for Android developed by bumptech named Glide as a library that recommended by Google. It has been used in many Google open source projects till now including Google I/O 2014 official application.

It succeeded in making me interested. I spent a whole night playing with it and decided to share my experience in this blog post. As a begining, I must say that it looks 90% similar to Picasso. To be more precise, I think it is something like a Picasso-clone.

Anyway it is quite different in details. You will learn how.

http://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en

Upvotes: 6

yshahak
yshahak

Reputation: 5096

Add ProgressBar to your XML where you put the ImageView , or do it programmatically. Then you could do:

 ProgressBar progressBar ; //initialize it as you dud with the imageView
    progressBar.setVisibility(View.VISIBLE);
    Picasso.with(context)
            .load(imageURL)
            .transform(transformation)
            .placeholder(R.drawable.ic_launcher)
            .error(R.drawable.ic_launcher)
            .into(viewHolder.imageView, new Callback() {
                @Override
                public void onSuccess() {
                    progressBar.setVisibility(View.GONE);
                }
                @Override
                public void onError() {
                }
            });

Upvotes: 2

Darshan Mistry
Darshan Mistry

Reputation: 3372

in your xml file you have to put progressbar above image, set visibility of progressbar visible and in your code

Picasso.with(context)
       .load(file)
       .into(imageView, new Callback() {
           @Override
           public void onSuccess() {
               progressbar.setVisibility(View.GONE);
           }
       });

when image is download you have to setVisibility(View.GONE) to progressbar

Upvotes: 5

Melvin Mauricio
Melvin Mauricio

Reputation: 387

I think you can use Target Class of Picasso

Target t = new Target() {
 @Override
 public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
         //hideProgress
}

@Override
public void onBitmapFailed(Drawable errorDrawable) {
           //hideProgress
}

 @Override
  public void onPrepareLoad(Drawable placeHolderDrawable) {

        //lshow Progress
 }
};

 Picasso.with(context)
.load(strImage)
.transform(transformation)
.placeholder(R.drawable.nothing_found)
.error(R.drawable.nothing_found)
.into(t);

Upvotes: 0

Related Questions