I guess you need to override notifyDataSetChanged method in your adapter and perform sorting right before calling its super. See below:
@Override
public void notifyDataSetChanged() {
//do your sorting here
super.notifyDataSetChanged();
}
Doing so will sort the list whenever you call notifyDataSetChanged
method to refresh list items. Otherwise, feed a sorted List/array to your adapter.
Or more preferably, use the sort
method available in your adapter to get the job done.
adapter.sort(new Comparator<String>() {
@Override
public int compare(String lhs, String rhs) {
return lhs.compareTo(rhs); //or whatever your sorting algorithm
}
});