--- 一组数据 ---
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();
}