title: Observe add and remove events from ArrayList
body: <p>In my applcation I'm trying to implement the MVVM design pattern with the Android Architecture library. For this I have created a <code>ViewModel</code> class with some <code>LiveData</code> objects in it.</p>
  
  <pre><code>public class NotesViewModel extends AndroidViewModel {
      private ArrayList&lt;Note&gt; notes;
  
      private MutableLiveData&lt;ArrayList&lt;Note&gt;&gt; allNotes;
      private MutableLiveData&lt;Note&gt; selectedNote;
  
      public LiveData&lt;Note&gt; getAllNotes() {
          return allNotes;
      }
  
      // ...
  </code></pre>
  
  <p>In my UI the user is able to add and remove notes. For this I thought it would be enough to create add and remove methods in my <code>NotesViewModel</code> and operate directly on the ArrayList like so:</p>
  
  <pre><code>    // ...
  
      public void addNote(Note note) {
          notes.add(note);
          allNotes.setValue(notes);
      }
  }
  </code></pre>
  
  <p>My problem with this solution is that I am not able to get the specific note which was removed or added by the user; only the whole list. So how should I do this? Do I have to create a <code>LiveData</code> object for each event the user can execute? Or is there a better way to do this?</p>