毕加索与Kotlin的回呼

Val*_*cia 1 android kotlin picasso

我正在用Kotlin制作一个Android应用程序,需要使用Picasso下载图像。我在下面看到了用于将动画设置为图像的Java代码,但是我无法将其转换为Kotlin,因为我不知道如何在“转为”功能中设置回调。

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
                    }
                });
Run Code Online (Sandbox Code Playgroud)

有人能帮我吗 ?

我的实际代码:

Picasso.with(context)
       .load(url)
       .into(imageDiapo, com.squareup.picasso.Callback)
Run Code Online (Sandbox Code Playgroud)

Kap*_*put 15

在最新版本中onError接收一个Exceptionas 参数并使用get()代替with()

  Picasso.get()
  .load(imageUrl)
  .into(imageView, object :Callback{
   override fun onSuccess() {
   Log.d(TAG, "success")
   }

   override fun onError(e: Exception?) {
   Log.d(TAG, "error")
   }
   })
Run Code Online (Sandbox Code Playgroud)

和在以前的版本

   Picasso.with(MainActivity::this)
   .load(imageUrl)
   .into(imageView, object: Callback {
                override fun onSuccess() {
                   Log.d(TAG, "success")
                }

                override fun onError() {
                  Log.d(TAG, "error")
                }
            })
Run Code Online (Sandbox Code Playgroud)


Sae*_*ari 5

Picasso.with(MainActivity::this)
       .load(imageUrl)
       .into(imageView, object: com.squareup.picasso.Callback {
                    override fun onSuccess() {
                        //set animations here

                    }

                    override fun onError() {
                        //do smth when there is picture loading error
                    }
                })
Run Code Online (Sandbox Code Playgroud)