从我的布局中,当用户点击视图时,我需要基于传递给布局的布尔值来调用其他方法。
我有类似的东西:
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="item"
type="com.example.MyObject" />
<variable
name="viewmodel"
type="com.example.MyViewModel" />
<variable
name="aBolean"
type="Boolean" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:onClick="@{()-> aBoolean ? viewmodel.methodOne() : viewmodel.methodTwo()}"
/>
</layout>
但是当我构建代码时,出现错误:
error: variable aBolean is already defined in method _internalCallbackOnClick(int,View)
我该怎么办?