Picasso image load callback

后端 未结 5 453
不思量自难忘°
不思量自难忘° 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:08

    Here is a simple example how to impement Picasso picture loading callback:

    Picasso.with(MainActivity.this)
                .load(imageUrl)
                .into(imageView, new com.squareup.picasso.Callback() {
                            @Override
                            public void onSuccess() {
                                //do smth when picture is loaded successfully
    
                            }
    
                            @Override
                            public void onError() {
                                //do smth when there is picture loading error
                            }
                        });
    

    On the latest Picasso's version, onError recives an Exception as parameter and uses get() instead of with()

    Picasso.get()
                .load(imageUrl)
                .into(imageView, new com.squareup.picasso.Callback() {
                            @Override
                            public void onSuccess() {
                                //do smth when picture is loaded successfully
    
                            }
    
                            @Override
                            public void onError(Exception ex) {
                                //do smth when there is picture loading error
                            }
                        });
    

提交回复
热议问题