title: LiveData Two-Way Binding
body: <p>I am trying to learn data binding, and this what I am not able to figure out.</p>
  <p>Inside DetailViewModel.kt</p>
  <pre><code>private val _event = MutableLiveData&lt;Event&gt;()
  
  init {
      appDatabase.eventDao().getEvent(eventId)
          .map { mapper.map(it) }
          .flowOn(Dispatchers.Default)
          .map { _event.value = it }
          .launchIn(viewModelScope)
  }
  
  val event: LiveData&lt;Event&gt;
      get() = _event
  
  val isReminderEnabled = Transformations.map(event) { it.alert != Alert.NEVER }
  </code></pre>
  <p>When I access <code>isReminderEnabled</code> inside layout xml, it shows are method reference.</p>
  <pre><code>&lt;com.google.android.material.switchmaterial.SwitchMaterial
      android:id=&quot;@+id/switchEnableReminder&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_gravity=&quot;end&quot;
      android:padding=&quot;@dimen/_8sdp&quot;
      android:checked=&quot;@{viewModel.isReminderEnabled()}&quot;
      app:useMaterialThemeColors=&quot;true&quot;
      tools:checked=&quot;true&quot; /&gt;
  </code></pre>
  <p>If I do <code> android:checked=&quot;@={viewModel.isReminderEnabled()}&quot;</code> build fails. How do I achieve two-way binding on <code>isReminderEnabled</code>? So that when the user toggles the switch I can update database accordingly.</p>
  <p><strong>UPDATE</strong></p>
  <p>I have changed</p>
  <pre><code>val isReminderEnabled = Transformations.map(event) { it.alert != Alert.NEVER 
  </code></pre>
  <p>to</p>
  <pre><code>val reminderEnabled: LiveData&lt;Boolean&gt;
      get() = Transformations.map(event) { it.alert != Alert.NEVER }
  </code></pre>
  <p>so now I can do this inside xml</p>
  <pre><code> android:checked=&quot;@{viewModel.reminderEnabled}&quot;
  </code></pre>
  <p>But for two-way binding to work I need <code>MutableLiveData</code>. How do I achieve that?</p>