Android: Data Binding Text not Updating
<p>I want the user to enter their name in an <code>EditText</code> and display <code>Hello {name}</code> inside a <code>TextView</code>. When I set the text of the <code>TextView</code> to be the observable property (<code>user.firstName</code>), the text updates. Even if I set the text to the <code>toString()</code> method of the model, it still works fine. However, if I instead use <code>viewModel.hello</code>, the text doesn't update. What am I missing?</p>

<p>Model:</p>

<pre><code>public class User extends BaseObservable {
    public String firstName;
    public String lastName;

    public User(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    @Bindable
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
        notifyPropertyChanged(BR.firstName);
    }

    @Bindable
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
        notifyPropertyChanged(BR.lastName);
    }

    @Override
    public String toString() {
        return getFirstName() + " " + getLastName();
    }
}
</code></pre>

<p>ViewModel:</p>

<pre><code>public class ViewModel {
    public  User user;

    public ViewModel() {
        user = new User("", "");
    }

    public String hello() {
        return "Hello " + user.toString();
    }

    public TextWatcher userNameTextWatcher() {
        return new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (editable.toString().length() == 0) {
                    user.setFirstName("");
                    user.setLastName("");
                    user.notifyChange();
                    return;
                }
                String[] name = editable.toString().split(" ");
                if (name.length == 1) {
                    user.setFirstName(name[0]);
                    user.setLastName("");
                    user.notifyChange();
                    return;
                }
                String firstName = name[0] + " ";
                for (int i = 0; i &lt; name.length - 2; i++) {
                    firstName = firstName + " " + name[i] + " ";
                }
                user.setFirstName(firstName);
                user.setLastName(name[name.length - 1]);
                user.notifyChange();
            }
        };
    }
}
</code></pre>

<p>Layout:</p>

<pre><code>&lt;data&gt;
    &lt;variable
        name="viewModel"
        type=".ViewModel"/&gt;
&lt;/data&gt;

&lt;TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:text="@{viewModel.hello}"/&gt;

    &lt;EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView"
        android:layout_marginTop="8dp"
        app:addEditTextWatcher="@{viewModel.userNameTextWatcher}"/&gt;
</code></pre>