林调用collections.sort ArrayList类任用对象的数组列表上,但它不会排序没有任何反应排序android系统不工作
这是IM调用集合排序
ArrayList<appointment> listoffappointments = new ArrayList<appointment>();
//then everytime on button click user adds a new appointment after setting the following code is executed
{
Calendar calendar1 = Calendar.getInstance();
calendar1.set(mYear, mMonth, mDay, temphour, tempmin);
appointment tempppt = new appointment(c2,tempstring1);
listoffappointments.add(tempppt);
Collections.sort(listoffappointments);
}
这里是怎么该类有人可以找到问题的感谢
import java.util.Calendar;
public class appointment implements Comparable<appointment> {
Calendar time;
String Text;
public appointment(Calendar tempc, String temptext) {
Text = temptext;
time = tempc;
}
public void settext(String text)
{
Text = text;
}
public String gettext()
{
return Text;
}
public String toString() {
return Text;
}
public Long gettimeofappt()
{
return time.getTimeInMillis();
}
@Override
public int compareTo(appointment o) {
return (this.gettimeofappt() < o.gettimeofappt()) ? -1: (this.gettimeofappt() > o.gettimeofappt()) ? 1:0 ;
}
}
哪里是你collections.sort电话吗? – Sree
在我的其他类中有类约会对象的数组列表 – theForgottenCoder
您应该在您的问题中包含该代码。 – nKn