How to sort array list by ascending and descending order in android.
This is simple, you just have to add below code in your activity or fragment where your arraylist is fetched from api or database.
To perform sort on array list you have to use collections, please see below code.
Collections.sort(arrBook,byPackage);
static final Comparator<Packages> byPackage = new Comparator<Packages>() { public int compare(Packages ord1, Packages ord2) { if(ord1.getIs_package().equals("1")){ return -1; //-1 to make package on top , 1 to make packages on bottom }else{ return 1; } } };
Comments
Post a Comment