How to sort listview items in descending order

后端 未结 3 2021
青春惊慌失措
青春惊慌失措 2020-12-21 14:07

So I have a listview where I wanted to sort the NumberOfRecords in descending order. I have a custom array adapter but I called my sorting class before I place a data in my

3条回答
  •  难免孤独
    2020-12-21 14:24

    Try with this Comparator.

    Comparator objComparator = new Comparator() {
        public int compare(Object o1, Object o2) {
            int no1 = Integer.parseInt((String) o1);
            int no2 = Integer.parseInt((String) o2);
            return  no1 < no2 ? -1 : no1 == no2 ? 0 : 1;
        }
    };
    Collections.sort(myIntegerList, objComparator);
    

提交回复
热议问题