Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Text field: autocomplete

Use an autocomplete text field to allow BlackBerry device users to select from a changing list of words that match the characters that they type in the field. Users can select one of the presented matches or continue typing to further restrict the available choices.

When you create an autocomplete text field, you must associate it with a BasicFilteredList object. The BasicFilteredList supplies the strings to compare against, which can be hard-coded or derived from data sources on a BlackBerry device, such as contacts, memos, and tasks.

Classes

AutoCompleteField

BasicFilteredList

Supported since

BlackBerry Java SDK 5.0

More information

For more information about autocomplete text fields, see the UI & Navigation Development Guide.

Example

This screen shows an autocomplete text field.

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.AutoCompleteField;
import net.rim.device.api.collection.util.*;


public class AutoCompleteFieldApp extends UiApplication 
{
    public static void main(String[] args) 
    {
        AutoCompleteFieldApp app = new AutoCompleteFieldApp();
        app.enterEventDispatcher();
    }
      
    AutoCompleteFieldApp()
    {
    	   pushScreen(new HomeScreen());
    }
}

class HomeScreen extends MainScreen
{
    public HomeScreen()
    {
								setTitle("Autocomplete Text Field Demo");
        BasicFilteredList filterList = new BasicFilteredList();
        String[] days = {"Monday","Tuesday","Wednesday",
        		               "Thursday","Friday","Saturday","Sunday"};
        filterList.addDataSet(1,days,"days",
              BasicFilteredList.COMPARISON_IGNORE_CASE);
        AutoCompleteField autoCompleteField = 
              new AutoCompleteField(filterList);
        add(autoCompleteField);
    }
}