Android picasso check if image url exist before load into imageView [duplicate]

送分小仙女□ 提交于 2019-12-05 20:53:47

Picasso supports placeholder and error images anyways:

Picasso.get()
    .load(url)
    .placeholder(R.drawable.user_placeholder)
    .error(R.drawable.user_placeholder_error)
    .into(imageView);

So, if all you want to archieve, is to show some error image, when loading does not work, that is all you need.

You can use com.squareup.picasso.Callback to listen for response.:

Picasso.with(getContext())
    .load(url)
    .placeholder(R.drawable.image_name) // Your dummy image...
    .into(imageView, new com.squareup.picasso.Callback() {
         @Override
         public void onSuccess() {
             // Image is loaded successfully...
         }

         @Override
         public void onError() {
             // Unable to load image, may be due to incorrect URL, no network...
         }
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!