排序列表在Android上复选框列 [英] Sorting a list with a checkbox column in android

查看:269
本文介绍了排序列表在Android上复选框列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在行包含四列的android列表视图。它可以由两列(ID,组),另外两个是一个彩色状态值和一个复选框进行排序。目前,该行正在使用比较的ID进行排序,分组然而,当我打电话通知只有这些值进行排序的颜色和复选框都没有。有没有一种方法排序基于行的名单?

添加了code的ID比较:

 公共静态类IDComparator实现比较<&MyObject的GT; {
        @覆盖
        公众诠释比较(为MyObject LHS,RHS为MyObject){
            如果(lhs.getID()== NULL){
                如果(rhs.getID()== NULL){
                    //等于
                    返回0;
                }其他{
                    // LHS为<
                    返回-1;
                }
            }
            如果(rhs.getID()== NULL){
                // LHS是>
                返回1;
            }
            //没有空
            如果(lhs.getID()&所述; rhs.getID()){
                返回-1;
            }否则如果(lhs.getID()> rhs.getID()){
                返回1;
            }其他{
                返回0;
            }
        }
    }

这个方法是从这里叫做:

  Col​​lections.sort(myList上,IDComparator);


解决方案

我使用Collection.sort在我的项目的排序是这样的:

  Col​​lections.sort(headerList,新的比较< HeaderVO>(){
        @覆盖
        公众诠释比较(HeaderVO E1,E2 HeaderVO){
              返回Double.valueOf(e2.getPNo())的compareTo(Double.valueOf(e1.getPNo()))。
        }
});

I have a listview in android that contains four columns in the row. It can be sorted by two columns (id, group) the other two are a color status value and a checkbox. Currently the rows are being sorted using comparators for the id, group however when I called notify only these values are sorted the color and checkbox are not. Is there a way to sort the list based on the row?

Added the code for the id comparator:

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;
            }
        }
    }

This method is called from here:

 Collections.sort(myList, IDComparator);

解决方案

I am using Collection.sort for sorting like this in my project :

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

这篇关于排序列表在Android上复选框列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆