gpt4 book ai didi

android - @Bindable 与方法错误数据绑定(bind)关联

转载 作者:太空宇宙 更新时间:2023-11-03 10:59:33 25 4
gpt4 key购买 nike

我正在使用数据绑定(bind)库通过方法使用属性 setter 来更新 TextView 的可见性

TextView :

<TextView
android:id="@+id/profileLblTtv"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="@string/profile_photo_gr"
android:gravity="center"
android:layout_marginTop="15dp"
android:visibility="@{viewmodel.kalase(), default=gone}"
app:layout_constraintTop_toBottomOf="@+id/reqfldsTtv"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />

和可绑定(bind) View 模型方法“kalase”:

@Bindable
public int kalase() {
return userRole != null && userRole.getId() != 0 ? View.VISIBLE : View.GONE;
}

我收到以下错误:“与方法关联的@Bindable 必须遵循 JavaBeans 约定 kalase()”。谁能告诉我出了什么问题?

最佳答案

一年半之后我很可能会迟到,但是......

错误是由于您在名称不符合 JavaBeans 约定的函数上有一个“@Bindable”标记。为了使其确认,只需调用您的方法 getKalase()(而不仅仅是 kalase())并在您的布局文件中将其称为 viewmodel.kalase (没有括号)

关于android - @Bindable 与方法错误数据绑定(bind)关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47754770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com