title: Sort listview with array adapter
body: <p>I have a listview connected to a custom array adapter. This list shows information received by a TCP connection which changes the dataSet...</p>
  
  <p>I am able to sort the listview with <code>sort (Comparator&lt;? super T&gt; comparator)</code>, but when the dataSet is changed, the listview is no more sorted... </p>
  
  <p>I can use <code>sort ()</code> every time the dataSet is changed, but I think this is not the best option...</p>
  
  <p>How can I do that? Any suggestions?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I am having problems in implementing the solutions presented...</p>
  
  <p><strong>MyComparatorB.java</strong></p>
  
  <pre><code>public class MyComparatorB implements Comparator&lt;DeviceB&gt; {
  
  private byte orderType;
  
  public MyComparatorB(byte type) {
  
      this.orderType = type;
  
  }
  
  public int compare(DeviceB lhs, DeviceB rhs) {
  
      int res = 0;
      if (orderType == SortType.ALPHA) {
              res = (lhs.getName()).compareTo(rhs.getName());
          }
          else if (orderType == SortType.LAST_ACT) {
              res = (rhs.getTime().getTime()).compareTo(lhs.getTime().getTime());
          }
          return res;
      }
  
  }
  </code></pre>
  
  <p><strong>Snippet of my customArrayAdapter.java</strong></p>
  
  <pre><code>    @Override
  public void notifyDataSetChanged() {
      super.notifyDataSetChanged();
  }
  
  
  //-----------Order the content of the arrayAdapter------------//
  public void sort(byte sortType) {
  
      super.sort(new MyComparatorB(sortType));
      notifyDataSetChanged();
  }
  </code></pre>
  
  <p><strong>In my MyActivity.java</strong></p>
  
  <pre><code>myDevAdapter.sort(SortType.ALPHA);
  </code></pre>
  
  <p>When I am debugging, the method <code>super.sort(new MyComparatorB(sortType));</code> is called and the constructor of MyComparatorB is called too. But the method <code>compare(DeviceB lhs, DeviceB rhs)</code> is never called and my arrayList is not sorted...
  What I am doing wrong?</p>