1

I'm using picasso in my application, but I'm facing one problem with that. I showing users profile images in Listview and if image is not present I want to show user's name initials at ImageView. I able to show profile image if present but for showing initials how I come to know that user don't have image.?

Akshay
  • 6,029
  • 7
  • 40
  • 59
  • You should handle with your model data. If(user.getImageUrl()!=null){//loadImageWithPicasso}else{//do what you want}. Or passing to picasso wrong url, and handle result passing callback to Picasso.load() overriding OnError. – encastellano Apr 13 '15 at 13:07
  • I'm preparing URL runtime so I don't know image available for user or not – Akshay Apr 13 '15 at 13:16
  • Then you should pass Callback to handle onError, when url not exist or another error. – encastellano Apr 13 '15 at 13:20
  • 4
    Something like this `Picasso.load(url).into(imageview, new Callback(){ @Override public void onSuccess() { } @Override public void onError() { //create ImageView with initials and pass to imageview } }); ` – encastellano Apr 13 '15 at 13:23
  • @encastellano write it as an answer – A-S Mar 25 '16 at 02:32
  • Something like this `Picasso.load(url).into(imageview, new Callback(){ @Override public void onSuccess() { } @Override public void onError() { //create ImageView with initials and pass to imageview } }); ` – encastellano Mar 25 '16 at 08:37
  • https://stackoverflow.com/questions/26548660/how-to-listen-for-picasso-android-load-complete-events – Mahmoud Hawas Mar 31 '19 at 13:53

1 Answers1

0

Make use of the placeholder() and error() method to load the default which you want to bind.

placeholder(), will be visible until the image is loaded. error(), will be visible when the error occurs during the loading from the url

.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error)
Fahim
  • 12,198
  • 5
  • 39
  • 57