Two-way databinding(in xml), ObservableField, BaseObservable , which one I should use for the two-way databinding?

前端 未结 2 1536
误落风尘
误落风尘 2021-02-05 10:30

I have used data-binding for a while, even now it is not available for JDK 8 and API 24 now. I still find a way to use the data binding in a easier way. But when I use the follo

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-05 11:15

    I feel that ObservableField approach is the way to go as there's no need to write getters/setters OR invoke notifyPropertyChanged.

    Also, if you have a custom object ObservableField studentField, and you use android:text="@{viewModel.studentField.name}, the text does get updated when you invoke studentField.set(newStudent).

    I find RxJava very useful. ObservableField can be easily converted to rx.Observable and vice versa. This allows use of Rx operators. In case you are interested, you can check the implementation here: FieldUtils.java

提交回复
热议问题