How to sort ArrayList while implementing Parcelable

后端 未结 2 995
轮回少年
轮回少年 2021-01-28 05:59

I am trying to sort the category arraylist with Collections.sort method but have no luck with it.

Here is my code:

public class Categories i         


        
2条回答
  •  猫巷女王i
    2021-01-28 06:12

    You can also use custom comparator:

    public class CategoriesComparator implements Comparator {
        @Override
        public int compare(Category category1, Category category2) {
            return category1.getSomeProperty().compareTo(category2.getSomeProperty());
        }
    }
    

    When you want to compare call this:

    Collections.sort(yourListCategories, new CategoriesComparator());
    

    Hope it helps!

提交回复
热议问题