[英]Kotlin: Code inside lamda function is unreachable while using library written in java
I have used an image picker library (written in Java). 我使用了一个图像选择器库(用Java编写)。 It provides the pick-result to the caller activity using the overridden function.
它使用重写函数为调用者活动提供pick-result。 As my caller activity is in kotlin, the overridden function gets converted into lambda function.
由于我的调用者活动在kotlin中,被覆盖的函数被转换为lambda函数。 But the code inside lambda function doesn't get executed.
但lambda函数内的代码不会被执行。 Is this a Java-to-Kotlin issue?
这是Java-to-Kotlin问题吗? Or is there a mistake in code?
或者代码中有错误吗?
Here is my code: 这是我的代码:
UtilLib.getPhoto(this, ChooseType.REQUEST_ANY)
.enqueue({ path ->
Picasso.with(applicationContext)
.load("file://$path")
.error(R.drawable.profile)
.resize(150, 150)
.into(ivProfilePic)
})
Library link: https://github.com/VinayRathod/UtilLib 图书馆链接: https : //github.com/VinayRathod/UtilLib
Here is the Java Code also which will work perfectly(Java). 这里的Java代码也可以完美地工作(Java)。
ChooseType chooseType =
((RadioButton) findViewById(R.id.choose_gallery)).isChecked() ? ChooseType.REQUEST_PICK_PICTURE :
((RadioButton) findViewById(R.id.choose_camera)).isChecked() ? ChooseType.REQUEST_CAPTURE_PICTURE :
ChooseType.REQUEST_ANY;
UtilLib.getPhoto(this, chooseType)
.enqueue(new OnImageChooserListener() {
@Override
public void onImageChoose(String path) {
ivPath.setText("" + path);
Glide.with(MainActivity.this).load(new File(path)).into(iv);
}
});
I tried your code like this : 我试过这样的代码:
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.vinay.utillib.UtilLib
import com.vinay.utillib.imagechooser.ChooseType
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
fab.setOnClickListener { view ->
UtilLib.getPhoto(this, ChooseType.REQUEST_ANY)
.enqueue({ path ->
Log.d("ok", "executed: $path")
})
}
}
}
And it seems to work : D/ok: executed: /storage/emulated/0/bichooser/1530711668746.myimage.png
它似乎工作:
D/ok: executed: /storage/emulated/0/bichooser/1530711668746.myimage.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.