title: Databinding: ObservableField of custom object it is not working properly
body: <p>In a test app I've one activity with one Edittext and a Button. Edittext is pointing to ObservableField of Person's name and on click of button, I'm modifying the person's name so that text inside the edittext should get changed. But changing the person name is not updating inside the edittext.</p>
  
  <p><strong>When it is working:</strong>
  It is working if I create a new Person object and set it to the observable field. </p>
  
  <p><strong>When it is not working</strong>
  But if I modify the same person object, does anybody know why it does not work in this case?</p>
  
  <p><strong>Person.java:</strong></p>
  
  <pre><code>public class Person {
      private int age;
      private String name;
  
      public Person(int age, String name) {
          this.age = age;
          this.name = name;
      }
  
      public int getAge() {
          return age;
      }
  
      public void setAge(int age) {
          this.age = age;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
  }
  </code></pre>
  
  <p><strong>PersonViewModel:</strong></p>
  
  <pre><code>public class PersonViewModel {
      public final ObservableField&lt;Person&gt; studentObservableField = new ObservableField&lt;&gt;();
  
      public PersonViewModel(Person person) {
          studentObservableField.set(person);
      }
  
      public void onButtonClick() {
  //          NOT WORKING
  //        Person person = studentObservableField.get();
  //        person.setName("Mohit");
  //        studentObservableField.set(person);
  
  //       WORKING FINE IN THIS CASE
           Person person = new Person(21, "Mohit");
           studentObservableField.set(person);
  
      }
  
  }
  </code></pre>
  
  <p><strong>layout_file.xml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;layout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
  
      &lt;data&gt;
          &lt;variable
              name="viewmodel"
              type="com.rahulchaurasia.databindingtest.PersonViewModel"/&gt;
      &lt;/data&gt;
  
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context="com.rahulchaurasia.databindingtest.MainActivity"&gt;
  
      &lt;EditText
          android:id="@+id/editText"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:ems="10"
          android:inputType="textPersonName"
          android:text="@{viewmodel.studentObservableField.name}"/&gt;
  
      &lt;Button
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Click me"
          android:onClick="@{()-&gt; viewmodel.onButtonClick()}"/&gt;
  
  &lt;/LinearLayout&gt;
  &lt;/layout&gt;
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          ActivityMainBinding activityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
          activityMainBinding.setViewmodel(new PersonViewModel(new Person(21, "Rohit")));
          activityMainBinding.executePendingBindings();
      }
  }
  </code></pre>