我正在尝试按字母顺序排列一系列电影,忽略大小写。我的应用程序允许用户将他/她自己的条目添加到 ListView 中已经初始化的电影数组中。这是片段:
Lab7_082588FetchDetails newMovie = new Lab7_082588FetchDetails();
IgnoreCaseComparator ignoreCase = new IgnoreCaseComparator();
newMovie.setTitle(data.getStringExtra(Lab7_082588Edit.TITLE_STRING));
newMovie.setGross(data.getStringExtra(Lab7_082588Edit.GROSS_STRING));
newMovie.setDate(data.getStringExtra(Lab7_082588Edit.DATE_STRING));
results.add(newMovie);
adapter.notifyDataSetChanged();
Collections.sort(results, ignoreCase);
但是最后一行的 .sort 部分给出了错误消息:
The method sort(List<T>, Comparator<? super T>) in the type Collections is not applicable for the arguments (ArrayList<Lab7_082588FetchDetails>, IgnoreCaseComparator)
另外,这是我的 IgnoreCaseComparator:
import java.util.Comparator;
class IgnoreCaseComparator implements Comparator<String> {
public int compare(String strA, String strB) {
return strA.compareToIgnoreCase(strB);
}
}
还有我的 Fetch Details 类:
public class Lab7_082588FetchDetails implements Comparable<Lab7_082588FetchDetails> {
private String title;
private String gross;
private String date;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getGross() {
return gross;
}
public void setGross(String gross) {
this.gross = gross;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
@Override
public int compareTo(Lab7_082588FetchDetails another) {
// TODO Auto-generated method stub
return title.compareTo(another.title);
}
}
我该如何补救?