我希望按日期按升序排序待办事项列表。你能帮我吗,我是android领域的初学者enter link description here
答案 0 :(得分:1)
尝试按日期的升序和降序
Collections.sort(arrayList, byDate);
方法升序和降序
static final Comparator<HomeModel> byDate = new Comparator<HomeModel>() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy,MM,dd");
public int compare(HomeModel ord1, HomeModel ord2) {
Date d1 = null;
Date d2 = null;
try {
d1 = sdf.parse(ord1.eventdate);
d2 = sdf.parse(ord2.eventdate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//return (d1.getTime() > d2.getTime() ? -1 : 1); //descending
return (d1.getTime() > d2.getTime() ? 1 : -1); //ascending
}
};
答案 1 :(得分:0)
getReports() {
return this.http.get(GlobalVariable.BASE_API_URL + 'report/l', {headers: this.headers}).map(res => res.json());
}
其中,document:any;
id:any;
ngOnInit() {
this.documentTypeService.getType(id).subscribe(data => {
document=data;
id= data.id;
console.log(id);
});
console.log(id); //undefined
}