BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 07-29-2009, 03:01 PM   #1
mishelka
New Member
 
Join Date: Jul 2009
Model: 9530
PIN: N/A
Carrier: 9530
Posts: 4
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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Voice Activated Listening Device Audio 150 Day Battery Spy Recorder 16 GB picture

Voice Activated Listening Device Audio 150 Day Battery Spy Recorder 16 GB

$109.00



AVNET ULTRAZED SOM ZYNQ ULTRASCALE+ XCZU3EG SYSTEM ON MODULE -  picture

AVNET ULTRAZED SOM ZYNQ ULTRASCALE+ XCZU3EG SYSTEM ON MODULE -

$98.67



1PCS Memory iButton IC DALLAS/MAXIM DS1994L-F5 DS1994L+F5 DS1994L-F5+ picture

1PCS Memory iButton IC DALLAS/MAXIM DS1994L-F5 DS1994L+F5 DS1994L-F5+

$183.20



New Factory Sealed AB 1756-L61 SER B ControlLogix 2MB Memory Controller 1756L61 picture

New Factory Sealed AB 1756-L61 SER B ControlLogix 2MB Memory Controller 1756L61

$304.69



SIMATIC, Memory Card, 4 Mbytes, 24 Mbytes, 256 Mbytes picture

SIMATIC, Memory Card, 4 Mbytes, 24 Mbytes, 256 Mbytes

$418.50



NEW Original Allen Bradley 2080-MEMBAK-RTC Memory Module With RTC Plug-In picture

NEW Original Allen Bradley 2080-MEMBAK-RTC Memory Module With RTC Plug-In

$291.75







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