我正在用Kotlin制作一个Android应用程序,需要使用毕加索下载图像.我在下面看到了用于将动画设置为图像的Java代码,但我无法将其转换为Kotlin,因为我不知道如何在"into"函数中设置回调.

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
                    }
                });

有人能帮帮我吗?

我的实际代码:

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

推荐答案

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
                    }
                })

Kotlin相关问答推荐

Kotlin—列出具有不同T的列表之间的操作'

只能在元素区域中点击的Jetpack Compose列

带有Spring Boot和Kotline的可嵌入实体

在Mapstruct中重用@映射定义

编译后的JavaFX应用程序立即以静默方式崩溃

可选的.在kotlin中不使用泛型参数

Criteria Api 中的 Kotlin 泛型

MyType.()在 Kotlin 中是什么意思?

有没有一种简单的方法可以将数组/列表中的每个元素相互相乘 - Kotlin?

Kotlin 插件之间的区别

是否可以通过超时暂停协程?

Saripaar formvalidation 在 kotlin 中第二次不起作用

如何在 kotlin @Parcelize 中使用 null

从列表中的每个对象中 Select 属性

将 jetpack compose 添加到现有元素

Kotlin 创建snackbar

Kotlin的web-framework框架

在Kotlin中使用@Service时引发异常

Kotlin reflect proguard SmallSortedMap

从 java 活动 *.java 启动 kotlin 活动 *.kt?