ListView(排序问题)

--- 一组数据 ---
public class Contact {
    private String price;
    private String time;
    private String tickit;

    public Contact(String price, String time, String tickit) {
        this.price = price;
        this.time = time;
        this.tickit = tickit;
    }

    public String getPrice() {
        return price;
    }

    public String getTime() {
        return time;
    }

    public String getTickit() {
        return tickit;
    }
}
--- 数据集合 ---
public class Contacts {
    private List<Contact> contacts = new ArrayList<>();

    public Contacts() {
        contacts.add(new Contact("313","07.10-13:25","剩余135张"));
        contacts.add(new Contact("153","08.10-15:42","剩余52张"));
        contacts.add(new Contact("533","09.10-16:05","剩余42张"));
        contacts.add(new Contact("424","10.10-17:26","剩余3张"));
    }

    public List<Contact> getContacts() {
        return contacts;
    }
}
--- 获取listview中的数据 ---
private List<Contact> list_data; 
Contacts contacts = new Contacts();
list_data = contacts.getContacts();

--- 列表排序 ---
Collections.sort(list_data, new Comparator<Contact>() {  
                    @Override
                    public int compare(Contact o1, Contact o2) {
                        	int order = Integer.parseInt(o1.getPrice())-Integer.parseInt(o2.getPrice());
                        	return order
                    }
                });
                adapter.notifyDataSetChanged();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值