Picasso image load callback

后端 未结 5 444
不思量自难忘°
不思量自难忘° 2020-12-08 13:20

I want to use Picasso to load three consecutive images one on top of each other in a listview. Using the methods Picasso provides makes this easy. However because these imag

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 14:16

    You can implement a callback with Picasso like shown below:

    ImageHandler.getSharedInstance(getApplicationContext()).load(imString).skipMemoryCache().resize(width, height).into(image, new Callback() {
                @Override
                public void onSuccess() {
                    layout.setVisibility(View.VISIBLE);
                }
    
                @Override
                public void onError() {
    
                }
            });
    }
    

    The implementation of my ImageHandler class is shown below:

    public class ImageHandler {
    
        private static Picasso instance;
    
        public static Picasso getSharedInstance(Context context)
        {
            if(instance == null)
            {
                instance = new Picasso.Builder(context).executor(Executors.newSingleThreadExecutor()).memoryCache(Cache.NONE).indicatorsEnabled(true).build();
            }
            return instance;
        }
    }
    

提交回复
热议问题