androidjava中使用kotlin库前如何实现回调(kotlin)

njthzxwz  于 2021-06-30  发布在  Java
关注(0)|答案(2)|浏览(371)

你能帮我在android(java)中集成lib吗?我有个问题 setOnRangeListener 从kotlin到java。
在java中

custCalendar.setOnRangeSelectedListener(...?);

kotlin中的函数示例

calendar_view.setOnRangeSelectedListener { startDate, endDate, startLabel, endLabel ->
    departure_date.text = startLabel
    return_date.text = endLabel
}

当为“单一”和“范围”类型选择“仅一天”时,将调用此函数

calendar_view.setOnStartSelectedListener { startDate, label ->
    departure_date.text = label
    return_date.text = "-"
}

fun setOnStartSelectedListener(callback: (startDate: Date, label: String) -> Unit) {
    mOnStartSelectedListener = callback
}

fun setOnRangeSelectedListener(callback: (startDate: Date, endDate: Date, startLabel: String, endLabel: String) -> Unit) {
    mOnRangeSelectedListener = callback
}

如何实现这个功能?

nr7wwzry

nr7wwzry1#

我想你可以在java类中调用它试试下面的代码

custCalendar.setOnRangeSelectedListener((startDate,label)->{

  // use parameters of function there

  return null
 });
wlwcrazw

wlwcrazw2#

在java中是这样的,但我看不到您接口的名称,所以我保留此选项:

custCalendar.setOnRangeSelectedListener(new OnRangeSelectedListener() {
    @Override
    public void onRangeSelected(@NonNull Object1 object, @NonNull Object2 object2) {

    }
  });

相关问题