Issue with higher order function as a binding adapter

后端 未结 4 665
野的像风
野的像风 2021-02-07 10:09

I am running into issues trying to take a function as a parameter in a binding adapter using Kotlin/Android databinding. This example code throws e: error: cannot generate

4条回答
  •  北海茫月
    2021-02-07 10:37

    Put apply plugin: 'kotlin-kapt' in build.gradle

    Then you can create Binding Adapter like

    @JvmStatic
    @BindingAdapter("onDelayedClick")
    fun onDelayedClick(view: View, function: () -> Unit) {
        // TODO: Do something
    }
    

    And XML Like

    
    

    And VM Like

    val testFunction =  {
        // TODO: Do something
    }
    

提交回复
热议问题