How to sort listview items in descending order

后端 未结 3 2020
青春惊慌失措
青春惊慌失措 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:13

    Okay, so I solved this by replacing the:

    p2.getNumberOfRecords().compareTo(p1.getNumberOfRecords())

    to:

    (int) Integer.parseInt(p2.getNumberOfRecords()) - Integer.parseInt(p1.getNumberOfRecords())
    

    So the simple compare of an integer in a String data type would not result correctly but to parse the string first by:

    Integer.parseInt(string)

    and get the true value of the number string.

提交回复
热议问题