your toString method probably isn't overridden for your objects representing the contacts. It will return a hash string for those objects, which varies every time your app is run.
You can fix this either of two ways:
- Override the
toString()
method in yourContact
object to return the contact's name (1), or - Change the
Comparator
toComparator<Contact>
so it getsContact
objects as parameters (2)
for (1), add this to your Contact class:
@Override public String toString() {
return get_contactFirstName();
}
for (2) you would end up with this Comparator implementation:
final static class ContactsListComparator implements Comparator<Contact> {
public int compare(Contact o1, Contact o2) {
return contact1.get_contactFirstName().compareTo(contact2.get_contactFirstName());
}
}
you don't even need to check for the <0 or >0, but you can just return whatever the String comparison gives.
Jorn
2009-07-12 14:47:16