Android:数据绑定,notifyPropertyChanged()无法正常工作?

Ash*_*win 14 android android-databinding

我正在使用Android的数据绑定库.我扩展了数据对象BaseObservable.

 public static class SimpleData extends BaseObservable implements Serializable {
    private String text, subText;
    private SpannableString totalText;
 @Bindable
    public SpannableString getTotalText() {
      return totalText;
    }

    public void setTotalText(SpannableString totalText) {
      this.totalText = totalText;
      notifyPropertyChanged(BR.totalText);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的xml也是绑定的

<TextView
              android:id="@+id/patient_name"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:layout_marginLeft="16dp"
              android:layout_toRightOf="@+id/patient_image"
              android:textColor="@color/primary_text"
              android:text="@{object.getTotalText()}"
              />
Run Code Online (Sandbox Code Playgroud)

绑定发生在初始值上.但是当我使用更改值时

object.setTotalText(someSpannableString);
Run Code Online (Sandbox Code Playgroud)

更改不会反映在文本视图中.可能是什么问题呢?

Len*_*Yan 7

使用字段名称而不是getter.

<TextView
              android:id="@+id/patient_name"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:layout_marginLeft="16dp"
              android:layout_toRightOf="@+id/patient_image"
              android:textColor="@color/primary_text"
              android:text="@{object.totalText}"/>
Run Code Online (Sandbox Code Playgroud)