title: How to update view model from the view in Android
body: <p>I am using <strong>Android Architecture Components</strong> in my app. The use case I am dealing with is actually very simple.</p>
  
  <p>Consider a simple Todo app where a todo-detail fragment is observing live data from a ViewModel holding an instance of currently open todo-item. </p>
  
  <p>Since this fragment is in edit mode, it will let user edit properties of the item.</p>
  
  <hr>
  
  <p><strong>Use Case 1</strong></p>
  
  <p>There is an image button with Grey colored Flag icon in it. When user taps on it, the item is marked as 'High Priority' and changes color of flag to Red.</p>
  
  <p>To achieve this, I am updating the property <code>viewModel.value.isHighPriority</code> to <code>true</code> on the view model instance which causes a change in data resulting in fragment listening to it. Fragment displays Flag color Red if <code>viewModel.value.isHighPriority = true</code>. So basically the UI event from view circles back to the view causing it to update.</p>
  
  <p><strong>Use Case 2</strong></p>
  
  <p>Consider a todo-item's title. It is shown in Android's <code>EditText</code>. In this case, how do I update view model with the data that user types in the box? I certainly do not want to highjack edit text's text changed events and handle character by character. That seems like an unnecessary hack to me.</p>
  
  <hr>
  
  <p>This whole thing is making me rethink the way I am handling updates to view model's live data from view. If what I am doing (2-way data binding) is not a good practice, please suggest me how to handle a case where view receives UI events that causes updates to data that the view itself is presenting at the moment.</p>