I'm looking at the new Data Binding plugin for Android and trying to integrate it in a project.
While reading about creating observable objects, i encountered the ObservableFields documentation that involves using self-contained observable objects example from documentation :
public class User extends BaseObservable {
public final ObservableField<String> firstName =
new ObservableField<>();
public final ObservableField<String> lastName =
new ObservableField<>();
public final ObservableInt age = new ObservableInt();
}
Above snippet would be a replacement of:
private static class User extends BaseObservable {
private String firstName;
private String lastName;
@Bindable
public String getFirstName() {
return this.firstName;
}
@Bindable
public String getFirstName() {
return this.lastName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
notifyPropertyChanged(BR.firstName);
}
public void setLastName(String lastName) {
this.lastName = lastName;
notifyPropertyChanged(BR.lastName);
}
}
Which is significantly less code; But when using Observable Fields and reference then from the XML layout like such:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="user" type="com.example.User"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.lastName}"
android:id="@+id/lastName"/>
</LinearLayout>
</layout>
I am getting this error:
../../databinding/ActivityMainBinding.java
Error:(127, 20) error: cannot find symbol variable lastName
And that is not verbose at all; Not using ObservableFields works like a charm.
Anyone facing this issue ? Thoughts?