Skip to content Skip to sidebar Skip to footer

How To Make Picasso Display Default Image When There Is An Invalid Path

I am having one issue on display a default image name here R.drawable.avatar_placeholder. When the link from webservice is non empty, but error 404. means there isn't any image on

Solution 1:

Try this,

Set error image as your place holder image

if(!PrefUtils.readString(Constant.PREF_PROFILE_IMAGE).equals("")) 
    {
        Picasso.with(context).load(PrefUtils.readString(Constant.PREF_PROFILE_IMAGE)).resize(200,200).centerCrop().error(R.drawable.avatar_placeholder).into(imgProfile);
    }
    else
    {
        Picasso.with(context).load(R.drawable.avatar_placeholder).error(R.drawable.avatar_placeholder).resize(200,200).centerCrop().into(imgProfile);
    }

gradle:

compile'com.squareup.picasso:picasso:2.5.2'

Solution 2:

Try this,

    Picasso.with(this)
     .load("YOUR IMAGE URL HERE")        
     .placeholder(DRAWABLE RESOURCE)       
     .error(DRAWABLE RESOURCE)      // Image to load when something goes wrong .resize(width, height)                            
     .rotate(degree)                                 
     .into(imageView);

Solution 3:

Picasso are not manging android memorey & slow , so i am higley recommend you to not to use it and instade of it just use Glide libeary .

(You can download image and make her circle with glide , download image a Bitmap and much more )

add to Gradle:

repositories { mavenCentral() // jcenter() works as well because it pulls from Maven Central }

dependencies { compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.android.support:support-v4:19.1.0' }

and just:

for load a pic:

Glide.with(this).load("URL").into(imageView);

and you can add a lot more functionality by glide , for example if you want a placeholder until the photo will load you are just adding .placeholder(): :

Glide.with(this).load("URL").placeholder(R.drawable.placeholder).into(imageView);

and if you want a to display photo incase of the photo you are trying to load is broken or have any problem , just add .error()

:

Glide.with(this).load("URL").error(R.drawable.error).placeholder(R.drawable.placeholder).into(imageView);

Post a Comment for "How To Make Picasso Display Default Image When There Is An Invalid Path"