Search code examples
androidkotlinpicasso

Picasso Callback with Kotlin


I'm making an Android app with Kotlin, and need to use Picasso to download images. I saw this Java code below for setting animations to images, but I can't convert it to Kotlin, cause I don't know how to set Callback in "into" function.

Picasso.with(MainActivity.this)
       .load(imageUrl)
       .into(imageView, new com.squareup.picasso.Callback() {
                    @Override
                    public void onSuccess() {
                        //set animations here

                    }

                    @Override
                    public void onError() {
                        //do smth when there is picture loading error
                    }
                });

Can someone help me ?

My actual code :

Picasso.with(context)
       .load(url)
       .into(imageDiapo, com.squareup.picasso.Callback)

Solution

  • Picasso.with(MainActivity::this)
           .load(imageUrl)
           .into(imageView, object: com.squareup.picasso.Callback {
                        override fun onSuccess() {
                            //set animations here
    
                        }
    
                        override fun onError(e: java.lang.Exception?) {
                            //do smth when there is picture loading error
                        }
                    })