BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-29-2009, 04:01 PM   #1 (permalink)
New Member
 
Join Date: Jul 2009
Model: 9530
PIN: N/A
Carrier: 9530
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Question Using find in SimpleSortingList

Please Login to Remove!

Hello ,
what should I do to use the find() method on a SimpleSortingList instance?
I have a SimpleSortingList of Stations, which look like this:

public Station {
private String name;
//....
//....something other
//....
public String getName() { return this.name; }
//....
}

I created a comparator:

private class StationNameComparator implements Comparator {
public int compare(Object o1, Object o2) {
if (o1 == null || o2 == null) {
return 0;
}
String n1 = ((Station)o1).getName().toLowerCase();
String n2 = ((Station)o2).getName().toLowerCase();
return n1.compareTo(n2);
}
}

so the sorting should work:

public void sortStationList() {
stationList.setSortComparator(new StationNameComparator());
stationList.reSort();
}

But what should I do to get find work? I need to find a Station according to some string in it's name (for example, I give a string "ri" and I get a station with a name "Paris").
According to the BlackBerry rim API the find() method returns:

If an object matching the given key exists in the vector (as determined by the comparator), the index of the matching element in the vector is returned. If a matching object could not be found, then -(insertionPoint + 1) is returned.

But what should I define in the comparator to get this to work with the Station names?

Please help me with this, thanks.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.