Home » Android » android – is there a way to load a default image in picasso

android – is there a way to load a default image in picasso

Posted by: admin May 14, 2020 Leave a comment


i cannot load an image in picasso from my drawable due to resons known only to picasso, so whever picasso fails to load i want to load a default image please help

            public Object instantiateItem(ViewGroup container, final int position) {
                 final Context context =getApplicationContext();
                 final ImageView imageView = new ImageView(getApplicationContext());
              int padding = context.getResources().getDimensionPixelSize(
              imageView.setPadding(padding, padding, padding, padding);

             ((ViewPager) container).addView(imageView, 0);
                      imageView.setTag("myview" + position);

                .into(imageView,new Callback() {

                    public void onError() {
                        // TODO Auto-generated method stub

                    public void onSuccess() {
                        // TODO Auto-generated method stub



iv included callback in the hope to do something but my brain is not working, any1 help

How to&Answers:

This is what i’m currently using (placeholder URL of course). It will try and load the image you provide in the “load()” part, will show the “placeholder()” part before it has downloaded the image, and if it fails it will show the “error()” part.

Personally i have both the placeholder() and error() part to show the same image, but you can load two different images.