I'm trying to arrange an array of movies in alphabetical order, ignoring case. My application allows the user to add his/her own entry into an already initialized array of movies in a ListView. Here is the snippet:
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);
However the .sort portion of the last line gives an error message:
The method sort(List<T>, Comparator<? super T>) in the type Collections is not applicable for the arguments (ArrayList<Lab7_082588FetchDetails>, IgnoreCaseComparator)
Also, this is my IgnoreCaseComparator:
import java.util.Comparator;
class IgnoreCaseComparator implements Comparator<String> {
public int compare(String strA, String strB) {
return strA.compareToIgnoreCase(strB);
}
}
And my Fetch Details Class:
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);
}
}
How do I remedy this?