Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

Picasso Library, Android: Using Error Listener

I'm playing around with the Picasso library for image loading, but I'm running into an issue. When an image fails to load, I want to hide the view rather than load in a default image. I noticed from the source that it looks like the only way to add a listener is from the builder, but the error method is never called when an image does fail to load. Anyone have any experience with this?

    iv = (ImageView) findViewById(R.id.imageView);

    Picasso.Builder builder = new Picasso.Builder(getApplicationContext());
    builder.listener(new Picasso.Listener() {

        @Override
        public void onImageLoadFailed(Picasso arg0, String arg1) {
            Log.e("Picasso Error", "Errored out, hiding view");
            iv.setVisibility(View.GONE);
        }
    });
    Picasso pic = builder.build();
    pic.load("thisshouldbreak.jpg").into(iv);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Picasso 2.0 allows you to attach a callback into a request.

https://github.com/square/picasso

The callback you are using is for "global" listener and it helps you debug errors that potentially happen due to a network load.

Use load(url).into(view, new Callback() {...}); in Picasso 2.0.

Remember to invoke cancelRequest(target) if you are using a Callback.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...