本文介绍了毕加索图书馆,Android的:使用错误监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在摆弄毕加索库图像加载,但我快成为一个问题。当图像加载失败,我想隐藏的观点,而不是负载的默认图像。我从它看起来像只有这样才能增加一个监听器是从制造商源注意到了,但错误的方法永远不会被调用时,图像就无法加载。任何人有任何这方面的经验吗?

  IV =(ImageView的)findViewById(R.id.imageView);

    Picasso.Builder建设者=新Picasso.Builder(getApplicationContext());
    builder.listener(新Picasso.Listener(){

        @覆盖
        公共无效onImageLoadFailed(毕加索为arg0,串ARG1){
            Log.e(毕​​加索错误,误块出来,躲在意见);
            iv.setVisibility(View.GONE);
        }
    });
    毕加索PIC = builder.build();
    pic.load(thisshouldbreak.jpg)插入(ⅳ)。
 

解决方案

毕加索2.0,您可以附加一个回调到一个请求。

https://github.com/square/picasso

您正在使用的回调是对全球监听器,它可以帮助你由于网络负荷调试错误可能发生。

使用负载(URL)。走进(视图,新的回调(){...}); 毕加索2.0

记住调用 cancelRequest(目标)如果您使用的是回调

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);
解决方案

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.

这篇关于毕加索图书馆,Android的:使用错误监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 10:51