I have two tables in mysql which bind \'Categories\' and \'products\' through ids \'id_catprods\' and \'ID_Cat\'. So far so good, I\'m working on Android with \"ExpandableListVi
Use
Collections.sort(arraylist);
or
list.sort(String::compareToIgnoreCase);
This will sort your arraylist and If you have Expandable list you have to use
Collections.sort(arraylist, new Comparator(){
@Override
public int compare(Modelclass o1, Modelclass o2) {
Collections.sort(o1.getsubarraylist(), new Comparator(){
@Override
public int compare(Modelclass o1, Modelclass o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
Collections.sort(o2.getsubarraylist(), new Comparator(){
@Override
public int compare(Modelclass o1, Modelclass o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
return o1.getName().compareToIgnoreCase(o2.getName());
// *This Sorts The Group's if you don't wanna sort group simply return 0*;
}
});
NOTE:- o1.getsubarraylist() & o2.getsubarraylist() is Child list's of a expandable list, Just add inner Collections.sort() for sorting expandable list's
or if you have Simple String arraylist
Collections.sort(arraylist, new Comparator(){
@Override
public int compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
}
});
I hope this helps someone in need....