title: Get last selected item of a ListView in JavaFX
body: <p>I need to get the last selected item of a ListView which is in MultipleSelectionMode in JavaFX. My code is below but it does not give me the last selected item. It seems to give a random item from the selected items.</p>
  
  <pre><code>addDocumentPagesListView.getSelectionModel().getSelectedItems().addListener(new ListChangeListener&lt;PageFile&gt;() {
  
          @Override
          public void onChanged(ListChangeListener.Change&lt;? extends PageFile&gt; change) {
              while (change.next()) {
  
                  if (change.wasAdded()) {
                      List &lt;? extends PageFile&gt; l = change.getAddedSubList();
                      Object o = l.get(l.size() - 1);                        
                      PageFile pf = (PageFile) o;
                      System.out.println("Showing pdf file: " + pf.getFile().getName());
                   }
              }
          }
      });
  </code></pre>