Autocomplete text field

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
Example This screen shows an autocomplete text field.

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

Code sample: Creating 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();
    	   pushScreen(new HomeScreen());

class HomeScreen extends MainScreen
    public HomeScreen()
								setTitle("Autocomplete Text Field Demo");
        BasicFilteredList filterList = new BasicFilteredList();
        String[] days = {"Monday","Tuesday","Wednesday",
        AutoCompleteField autoCompleteField = new AutoCompleteField(filterList);
Next topic: AutoText edit field
Previous topic: Search field

Was this information helpful? Send us your comments.