我正在使用android数据绑定库和MVVM体系结构。在xml布局中,我定义了一个名为myModel的viewModel变量。该布局有几个TextInputEditText,我使用了以下自定义绑定适配器:
//makes the drawable_right of the TextView clickable
@SuppressLint("ClickableViewAccessibility")
@BindingAdapter("onDrawableRightClick")
inline fun TextView.setOnDrawableRightClick(crossinline f: () -> Unit) {
this.setOnTouchListener(View.OnTouchListener { _, event ->
if (event.action == MotionEvent.ACTION_UP) {
if (event.rawX >= this.right - this.paddingRight - this.compoundDrawables[DRAWABLE_RIGHT].bounds.width()) {
f()
return@OnTouchListener true
}
}
false
})
}
Run Code Online (Sandbox Code Playgroud)
在布局中,我app:onDrawableRightClick="@{() -> viewModel.doThing()}"仅添加到TextInputEditText之一,然后单击运行。一切正常,没问题。
现在,我返回并添加app:onDrawableRightClick="@{() -> viewModel.doOtherThing()}"到第二个TextInputEditText。这次编译失败,显示为error: missing return statement。
该代码块中的错误在MyFragmentBindingImpl(生成)中:
public final kotlin.Unit _internalCallbackInvoke(int sourceId ) {
switch(sourceId) {
case 1: {
// localize variables for thread safety
// …Run Code Online (Sandbox Code Playgroud) java android kotlin android-databinding android-binding-adapter