Picasso Library, Android: Using Error Listener

后端 未结 6 1559
说谎
说谎 2020-11-29 05:11

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 de

6条回答
  •  野性不改
    2020-11-29 05:46

    When we got error, error goes to onError method then we handle it!

    private void getAvatar(){
            Picasso.with(this)
                    .load(Links.GET_AVATAR + ".jpg")
                    .into(imgUserAvatar, new Callback() {
                        @Override
                        public void onSuccess() {
    
                        }
    
                        @Override
                        public void onError() {
                            imgUserAvatar.setImageResource(R.drawable.icon_profile_default);
                        }
                    });
    }
    

提交回复
热议问题