I want to sort items of the ListView by product name. I have a vector called \"data\" which is a type of class.
The class I have is:
public static cl
If you're using an ArrayAdapter
, you can call sort on the adapter and pass a Comparator
. How you implement your Comparator
is up to you.
Edit I:
You shouldn't need to override sort
... the ArrayAdapter
class implements that for you. All you need to do is create your own Comparator
that will sort the generic type objects the way you want them to appear. Also, if you sort the list during runtime, you might need to notify the application that the data set has changed. Your code should work correctly if you use this approach.
adapter = new CustomAdapter(this, R.layout.list,R.id.title, data);
adapter.sort(new Comparator() {
public int compare(RowData arg0, RowData arg1) {
return arg0.mProductName.compareTo(arg1.mProductName);
}
});
setListAdapter(adapter);
adapter.notifyDataSetChanged();