@Bindable related to method error data binding

I am using a data binding library to update TextView visibility with an attribute installer using a method

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" />

and bindable viewmodel 'kalase' method:

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

I get the following error: "@Bindable associated with the method must follow the JavaBeans kalase () convention." Can someone tell me what is going wrong?

+4
source share
2 answers

I think you are using this method in a class that extends the BaseObservable class . in these classes you should use a method that oversees your fields

UserRole userRole;

public void setUserRole(UserRole userRole) {
    this.userRole = userRole;
    notifyPropertyChanged(BR.userRole);
}

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

After a year and a half, I could well be late for the party, but ...

- , "@Bindable" , JavaBeans. getKalase() ( kalase()) viewmodel.kalase ( )

0

Source: https://habr.com/ru/post/1690556/


All Articles