title: Sorting of ListView by Name of the Product using Custom adaptor?
body: <p>I want to sort items of the ListView by product name. I have a vector called "data" which is a type of class.</p>
  
  <p>The class I have is:</p>
  
  <pre><code>public static class RowData implements Comparable&lt;RowData&gt;{
      public String mProductName;
      protected int mId;
  
      protected int mOnHand;
      protected double mPrice;
      protected boolean mIsColleaction;
      protected boolean mIsPrePack;
  
      RowData(int id ,String productName,int onhand,double price,boolean IsColleaction, boolean IsPrePack) {
          mId= id;
          mProductName= productName;
          mOnHand =onhand;
          mPrice = price;
          mIsColleaction =IsColleaction;
          mIsPrePack = IsPrePack;
      }
  
      @Override
      public String toString() {
          return mProductName;
      }
  
      public int compareTo(RowData other) {
          return mProductName.compareTo(other.mProductName);
      }
  
      public static Comparator&lt;RowData&gt; COMPARE_BY_PRODUCTNAME = new Comparator&lt;RowData&gt;() {
          public int compare(RowData one, RowData other) {
              return one.mProductName.compareTo(other.mProductName);
          }
      };
  }
  </code></pre>
  
  <p>and i have taken a custom adapter which extends <code>ArrayAdapter&lt;RowData&gt;</code>.</p>
  
  <p>My sorting code i have written in <code>onCreate()</code> is as follows,</p>
  
  <pre><code>Collections.sort(data, RowData.COMPARE_BY_PRODUCTNAME);
  adapter = new CustomAdapter(this, R.layout.list,R.id.title, data);
  
  setListAdapter(adapter);
  adapter.notifyDataSetChanged();
  </code></pre>
  
  <p>I have to use a custom adaptor because to show price of the product as well as quantity in hand of the product </p>
  
  <p>the data which is a vector of type <code>RowData</code> I am getting after debugging in sorted order of the product Name which I want but when bind to the <code>ListView</code> it is not displaying in sorted order.</p>
  
  <p>I am new to android please help me.</p>
  
  <hr>
  
  <p>Thanks Alex Lockwood, I am using custom adapter of type <code>ArrayAdaptor&lt;Class&gt;</code>.</p>
  
  <p>In my <code>onCreate()</code> method I am implementing sorting method like the below,</p>
  
  <pre><code>adapter = new CustomAdapter(this, R.layout.list,R.id.title, data);
  
  adapter.sort(new Comparator&lt;RowData&gt;() {
      public int compare(RowData arg0, RowData arg1) {
          return arg0.mProductName.compareTo(arg1.mProductName);
      }
  });
  
  setListAdapter(adapter);
  </code></pre>
  
  <p>In my <code>customAdaptor</code> class, I have to override <code>sort</code> like this,</p>
  
  <pre><code>public void sort(Comparator&lt;? super RowData&gt; comparator) {
      // TODO Auto-generated method stub
      super.sort(comparator);
  }
  </code></pre>
  
  <p>Please help me if you can modify the above code or suggest me your code.</p>
  
  <p>Thanks in advance.</p>