这是我得到的错误:
> Task :app:kaptDevDebugKotlin FAILED
location: package ...app.databinding
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:kaptDevDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)
这是我的自定义 BindingAdapter:
@Suppress("unused")
object BindingAdapters {
@JvmStatic
@BindingAdapter(value = ["isVisible", "hide"], requireAll = false)
fun setVisible(view: View, show: Boolean?, hide: Boolean?) {
view.visibility = if (show != false) View.VISIBLE else if (hide != false) View.INVISIBLE else View.GONE
}
...
}
布局中的用法:
<include
layout="@layout/view_loading_small"
isVisible="@{viewModel.isLoading()}" ... />
在哪里:
private val _isLoading = MutableLiveData<Boolean>(false)
val isLoading: LiveData<Boolean> = _isLoading
我不知道发生了什么,我一直使用这种方法没有问题。今天我添加了“隐藏”参数和 BAM KaptExecution InvocationTargetException
。
唯一的解决方法是将我的BindingAdapter
对象更改为:
@JvmStatic
@BindingAdapter(value = ["isVisible", "hide"], requireAll = false)
fun setVisible(view: View, show: Boolean?, hide: Boolean?) {
view.visibility = if (show != false) View.VISIBLE else if (hide != false) View.INVISIBLE else View.GONE
}
@JvmStatic
@BindingAdapter(value = ["isVisible"])
fun setVisible(view: View, show: Boolean) {
setVisible(view, show, false)
}
但这没有意义,不是requireAll = false
应该解决这个问题吗?我在这里想念什么?