2

I'm trying to use two-way data-binding on an EditText. However, my variable type is a nullable Float (I'm using Kotlin by the way). I keep getting databinding error, cannot find the getter for android:text with value type of Float.

android:text='@={travelRecord.weeksOfStay+""}'

Would not work because it will come up as null, but I want it as blank when the variable is null.

android:text='@={travelRecord.weeksOfStay? "":travelRecord.weeksOfStay+""}'

Would not work because it won't recognize two way data binding.

I read somewhere about BindingAdapter and InverseBindingAdapter, but cannot get it to work. How do I specify them to recognize my EditText?

<EditText
        android:id="@+id/length_of_stay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="numberDecimal"
        android:text='@={travelRecord.weeksOfStay}' />
hook38
  • 3,899
  • 4
  • 32
  • 52

0 Answers0