0

I want to add an Search Box in list Field. so that When i Enter a letter, then it will show the names starting with the letter 'A' , and so on. Iam using Vector to save the list of contacts same as the image shown : enter image description here

meera
  • 199
  • 3
  • 15

2 Answers2

1

If you want to select from the Contacts, use the ContactList.choose() method.

DO NOT try to iterate through the entire contacts your self every time. Remember there are lot of people having thousands of contacts and your code will be very unresponsive.

See: https://stackoverflow.com/a/4436816/371534

However, if you want to have 'filter as you type' kind of functionality with some other data, use the KeywordFilterField. You can get a sample code for it in the BlackBerry JDK samples.

Community
  • 1
  • 1
Adwiv
  • 1,283
  • 9
  • 15
0

Set a FieldChangeListener (or listen for alphanumeric key presses) to your EditField. Then refresh the list each time. Filtering on entries starting with the string contained in the EditField.

I wrote this on a pc without the Blackberry plugin installed, so couldn't test it, but it should be something like this.

String prefix = editField.getText();
Enumeration e = list.items();
while(e.hasMoreElements())
{
    PIMItem item = (PIMItem) e.nextElement();
    String name = item.getString(PIMItem.NAME,0);
    if (name.startsWith(prefix))
    {
        //TODO display on screen
    }
}
Kevin
  • 1,626
  • 16
  • 30