BlackBerry Forums Support Community

Closed Thread
LinkBack Thread Tools
Old 07-29-2009, 03:01 PM   #1 (permalink)
New Member
Join Date: Jul 2009
Model: 9530
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; }

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());

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.

Copyright 2004-2016
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.