【问题标题】:Sorting a list with a checkbox column in android在android中对带有复选框列的列表进行排序
【发布时间】:2015-08-05 11:22:13
【问题描述】:

我在 android 中有一个列表视图,其中包含一行中的四列。它可以按两列(id、group)排序,另外两列是颜色状态值和复选框。目前正在使用比较器对行进行排序,组但是当我调用通知时,只有这些值被排序,颜色和复选框不是。有没有办法根据行对列表进行排序?

添加了 id 比较器的代码:

public static class IDComparator implements Comparator<MyObject> {
        @Override
        public int compare(MyObject lhs, MyObject rhs) {
            if (lhs.getID() == null) {
                if (rhs.getID() == null) {
                    //equal
                    return 0;
                } else {
                    //lhs is <
                    return -1;
                }
            }
            if (rhs.getID() == null) {
                //lhs is >
                return 1;
            }
            //neither null
            if (lhs.getID() < rhs.getID()) {
                return -1;
            } else if (lhs.getID() > rhs.getID()) {
                return 1;
            } else {
                return 0;
            }
        }
    }

从这里调用这个方法:

 Collections.sort(myList, IDComparator);

【问题讨论】:

  • 放上你的比较器代码

标签: android sorting listview comparator


【解决方案1】:

我在我的项目中使用 Collection.sort 进行这样的排序:

 Collections.sort(headerList, new Comparator<HeaderVO>() {
        @Override
        public int compare(HeaderVO e1, HeaderVO e2) {
              return Double.valueOf(e2.getPNo()).compareTo(Double.valueOf(e1.getPNo()));
        }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 2021-12-24
    • 2019-09-08
    • 1970-01-01
    相关资源
    最近更新 更多