Development Guide

Local Navigation

Create an autocomplete text field from a data set

  1. Import the required classes and interfaces.
    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.*;
  2. Create the application framework by extending the UiApplication class. In main(), create an instance of the new class and invoke enterEventDispatcher() to enable the application to receive events. In the constructor, invoke pushScreen() to display the custom screen for the application. The HomeScreen class, described in step 3, represents the custom screen.
    public class AutoCompleteFieldApp extends UiApplication 
    {
        public static void main(String[] args) 
        {
            AutoCompleteFieldApp app = new AutoCompleteFieldApp();
            app.enterEventDispatcher();
        }
          
        AutoCompleteFieldApp()
        {
        	   pushScreen(new HomeScreen());
        }
    }
  3. Create the custom screen by extending the MainScreen class.
    class HomeScreen extends MainScreen
    {
        public HomeScreen()
        {
        }
    }
  4. In the constructor, create a BasicFilteredList object. Create a String array and store the strings that you want to match against in the array. In this example, the strings are days of the week. Invoke addDataSet() to bind the data in the array to the BasicFilteredList.
    BasicFilteredList filterList = new BasicFilteredList();
    String[] days = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
    filterList.addDataSet(1,days,"days",BasicFilteredList.COMPARISON_IGNORE_CASE);
  5. In the constructor, create an AutoCompleteField object. Pass an instance of the BasicFilteredList to the AutoCompleteField constructor to bind the BasicFilteredList to the autocomplete text field. Invoke add() to add the field to the screen.
    AutoCompleteField autoCompleteField = new AutoCompleteField(filterList);
    add(autoCompleteField);

Create an autocomplete text field from a data source

  1. Import the required classes and interfaces.
    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.*;
  2. Create the application framework by extending the UiApplication class. In main(), create an instance of the new class and invoke enterEventDispatcher() to enable the application to receive events. In the application constructor, invoke pushScreen() to display the custom screen for the application. The HomeScreen class represents the custom screen that is described in step 3.
    public class AutoCompleteFieldApp extends UiApplication 
    {
        public static void main(String[] args) 
        {
            AutoCompleteFieldApp app = new AutoCompleteFieldApp();
            app.enterEventDispatcher();
        }
        public AutoCompleteFieldApp()
        {
        	   pushScreen(new HomeScreen());
        }
    }
  3. Create the custom screen for the application by extending the MainScreen class.
    class HomeScreen extends MainScreen
    {
        public HomeScreen()
        {
        }
    }
  4. In the screen constructor, create a BasicFilteredList object. Invoke addDataSource() to bind a data source to the BasicFilteredList. In this example, the data is contact information and the data source is the contact list. The first argument that you pass to addDataSource() is a unique ID. The second argument binds the BasicFilteredList object to a data source. The third argument specifies the set of data source fields to compare with. The fourth argument specifies the set of data source fields to make available when a match is found. In this example, the fields to compare with are the same as the fields to make available when a match is found. The fifth argument specifies the primary display field. The sixth argument specifies the secondary display field and is set to -1 if you do not want to use it. The final argument specifies a name for the BasicFilteredList; its value is generated automatically if you specify null.
    BasicFilteredList filterList = new BasicFilteredList();
            filterList.addDataSource(
            	1,
            	BasicFilteredList.DATA_SOURCE_CONTACTS,
    
                BasicFilteredList.DATA_FIELD_CONTACTS_NAME_FULL | 
                BasicFilteredList.DATA_FIELD_CONTACTS_COMPANY | 
                BasicFilteredList.DATA_FIELD_CONTACTS_EMAIL,
    
                BasicFilteredList.DATA_FIELD_CONTACTS_NAME_FULL | 
                BasicFilteredList.DATA_FIELD_CONTACTS_COMPANY | 
                BasicFilteredList.DATA_FIELD_CONTACTS_EMAIL,
    
                BasicFilteredList.DATA_FIELD_CONTACTS_NAME_FULL,
                -1,
                null);
  5. In the screen constructor, create an AutoCompleteField object. Pass the BasicFilteredList object that you created in step 4 to the AutoCompleteField constructor to bind the BasicFilteredList to the autocomplete text field. Invoke add() to add the field to the screen.
    AutoCompleteField autoCompleteField = new AutoCompleteField(filterList);
    add(autoCompleteField);

Using data sources and fields with an autocomplete text field

You can use the AutoCompleteField class and the BasicFilteredList class to compare the text that a user types in an autocomplete text field with the values of fields in a specified data source. You specify the fields to use and their data sources by using a BasicFilteredList object that you pass as an argument to the constructor of the AutoCompleteField class.

Data source

Fields

DATA_SOURCE_APPOINTMENTS

  • DATA_FIELD_APPOINTMENTS_ALL
  • DATA_FIELD_APPOINTMENTS_ATTENDEES
  • DATA_FIELD_APPOINTMENTS_ORGANIZER
  • DATA_FIELD_APPOINTMENTS_SUBJECT

DATA_SOURCE_CONTACTS

  • DATA_FIELD_CONTACTS_ADDRESS_ALL
  • DATA_FIELD_CONTACTS_ADDRESS_HOME
  • DATA_FIELD_CONTACTS_ADDRESS_WORK
  • DATA_FIELD_CONTACTS_ANNIVERSARY
  • DATA_FIELD_CONTACTS_BIRTHDAY
  • DATA_FIELD_CONTACTS_CATEGORIES
  • DATA_FIELD_CONTACTS_COMPANY
  • DATA_FIELD_CONTACTS_EMAIL
  • DATA_FIELD_CONTACTS_FAX
  • DATA_FIELD_CONTACTS_JOB_TITLE
  • DATA_FIELD_CONTACTS_NAME_FULL
  • DATA_FIELD_CONTACTS_NAME_FIRST
  • DATA_FIELD_CONTACTS_NAME_LAST
  • DATA_FIELD_CONTACTS_NOTES
  • DATA_FIELD_CONTACTS_PAGER
  • DATA_FIELD_CONTACTS_PHONE_ALL
  • DATA_FIELD_CONTACTS_PHONE_HOME
  • DATA_FIELD_CONTACTS_PHONE_HOME2
  • DATA_FIELD_CONTACTS_PHONE_MOBILE
  • DATA_FIELD_CONTACTS_PHONE_OTHER
  • DATA_FIELD_CONTACTS_PHONE_WORK
  • DATA_FIELD_CONTACTS_PHONE_WORK2
  • DATA_FIELD_CONTACTS_PIN

DATA_SOURCE_MEMOS

  • DATA_FIELD_MEMOS_TITLE

DATA_SOURCE_MESSAGES

  • DATA_FIELD_MESSAGES_ALL
  • DATA_FIELD_MESSAGES_RECIPIENT
  • DATA_FIELD_MESSAGES_SENDER
  • DATA_FIELD_MESSAGES_SUBJECT

DATA_SOURCE_MUSIC

  • DATA_FIELD_MUSIC_ALL
  • DATA_FIELD_MUSIC_ALBUM
  • DATA_FIELD_MUSIC_ARTIST
  • DATA_FIELD_MUSIC_GENRE
  • DATA_FIELD_MUSIC_PLAYLIST
  • DATA_FIELD_MUSIC_SONG

DATA_SOURCE_PICTURES

  • DATA_FIELD_PICTURES_TITLE

DATA_SOURCE_RINGTONES

  • DATA_FIELD_RINGTONES_TITLE

DATA_SOURCE_TASKS

  • DATA_FIELD_TASKS_TITLE

DATA_SOURCE_VIDEOS

  • DATA_FIELD_VIDEOS_TITLE

DATA_SOURCE_VOICENOTES

  • DATA_FIELD_VOICENOTES_TITLE
Next topic: Spin boxes
Previous topic: Autocomplete text field

Was this information helpful? Send us your comments.