title: android - using dataBinding, on Activity instead of layout
body: <p>I am working in MVVM design pattern.
  I want to use dataBinding or RXJava in order to notify the View when the model has changed.
  dataBinding can do it inside <strong>xml</strong>.
  but i want to notify the <strong>Activity</strong> on a change in the model and do something  more complicated.
  let's assume i want my TextView to change color when text in not empty.
  can you help me to do it via dataBinding or RXJava ?</p>
  
  <p>here is my code:</p>
  
  <p>xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;data&gt;
  
      &lt;variable
          name="viewModel"
          type="edi.com.mydatabindingsimple.MyViewModel" /&gt;
  &lt;/data&gt;
  
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"&gt;
  
      &lt;EditText
          android:id="@+id/editText"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:ems="10"
          android:inputType="textPersonName"
          android:text="@={viewModel.txt}" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@={viewModel.txt}" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>Activity</p>
  
  <pre><code>import android.databinding.DataBindingUtil;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  
  import edi.com.mydatabindingsimple.databinding.ActivityMainBinding;
  
      public class MainActivity extends AppCompatActivity {
  
          MyViewModel viewModel = new MyViewModel();
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              final ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
              binding.setViewModel(viewModel);
          }
      }
  </code></pre>
  
  <p>viewModel</p>
  
  <pre><code>    import android.databinding.BaseObservable;
  import android.databinding.Bindable;
  
  
  
  public class MyViewModel extends BaseObservable{
      private String txt;
  
      @Bindable
      public String getTxt() {
          return txt;
      }
  
      public void setTxt(String txt) {
          this.txt = txt;
          notifyPropertyChanged(edi.com.mydatabindingsimple.BR.txt);
      }
  
  }
  </code></pre>