Help Center
Local Navigation
- Creating user interfaces
- Screens
- Touch screen orientation and direction
- Working with the accelerometer of a BlackBerry device
- Types of accelerometer data
- Accelerometer
- Retrieve accelerometer data at specific intervals
- Query the accelerometer when the application is in the foreground
- Query the accelerometer when the application is in the background
- Store accelerometer readings in a buffer
- Retrieve accelerometer readings from a buffer
- Get the time a reading was taken from the accelerometer
- UI components
- Add a UI component to a screen
- Create a dialog box
- Create a bitmap
- Create a button
- Create a list
- Create a drop-down list
- Create a search field
- Create a check box
- Create an option button
- Create a date field
- Creating a text field
- Create a progress indicator
- Create a text label
- Create a list box
- Create a field to display a tree view
- Add a UI component to a screen
- Create a custom field
- Add a menu item to a BlackBerry Device Software application
- Adding a menu item to a BlackBerry Device Software application
- Register a menu item
- Arrange UI components
- Events
- Touch screen events
- Types of touch screen events
- Respond to touch screen events
- Respond to system events while the user touches the screen
- Respond to a user sliding a finger up quickly on the screen
- Respond to a user sliding a finger down quickly on the screen
- Respond to a user sliding a finger to the left quickly on the screen
- Respond to a user sliding a finger to the right quickly on the screen
- Respond to a user clicking the screen
- Respond to a user touching the screen twice quickly
- Respond to a user touching and dragging an item on the screen
- Respond to a user touching the screen lightly
- Respond to a scroll action
- Respond to a user touching the screen in two locations at the same time
- Keyboard on a BlackBerry device with a touch screen
- Spell check
- Accessibility
- Integrating with assistive technology software
- Notifying an assistive technology application when the UI changes
- UI changes that trigger a notification to an assistive technology application
- UI component states and properties
- Provide an assistive technology application with information about a UI change
- Provide an assistive technology application with information about text changes
- Provide an assistive technology application with access to information from a table
- Provide an assistive technology application with access to numeric values
- Enable an assistive technology application to receive notification of UI events
- Storing data
- Creating connections
- Managing applications
- Using custom messages and folders in the message list
- Applications for push content
- Localizing BlackBerry device applications
- Controlling access to APIs and application data
- Testing a BlackBerry device application
- Packaging and distributing a BlackBerry Java Application
- Glossary
- Provide feedback
- Legal notice
BlackBerry Manuals & Help
>
Documentation for Developers
>
Java Development Guides and API Reference
>
Development Guide - BlackBerry Java Development Environment - 4.7.0
Create a search field
You can create an application that uses the KeywordFilterField class, included in the net.rim.device.api.ui.component package, to provide a UI field that consists of a single text input field and a list of selectable elements. As users type text in a search field, the application
filters the elements in the list
that begin with the search text. For more information about using the KeywordFilterField class,
see the KeywordFilterFieldDemo sample application, included with the BlackBerry® Java® Development Environment version 4.3.1 or later.
- Import the following classes:
- Import the net.rim.device.api.ui.component.KeywordProvider interface.
- Create variables. In the following code sample, CountryList extends the SortedReadableList class and implements the KeywordProvider interface.
private KeywordFilterField _keywordField; private CountryList _CountryList; private Vector _countries;
- To create a list of selectable text items, populate a vector with data from a text file.
_countries = getDataFromFile();
- Create an instance of a class that extends the SortedReadableList class.
_CountryList = new CountryList(StringComparator.getInstance(true),_countries);
- To specify the elements of the list, create a new instance of a KeywordFilterField object.
_keywordField = new KeywordFilterField();
- Invoke KeywordFilterField.setList().
_keywordField.setList(_CountryList, _CountryList);
- Set a label for the input field of the KeywordFilterFIeld.
_keywordField.setLabel("Search: "); - Create the main screen of the application and add a KeywordFilterField to the main screen.
KeywordFilterDemoScreen screen = new KeywordFilterDemoScreen(this,_keywordField); screen.add(_keywordField.getKeywordField()); screen.add(_keywordField); pushScreen(screen);
- To create a method that populates and returns a vector of Country objects containing data from text file, in the method signature, specify Vector as the return type.
public Vector getDataFromFile()
- Create and store a reference to a new Vector object.
Vector countries = new Vector();
- Create an input stream to the text file.
InputStream stream = getClass().getResourceAsStream("/Data/CountryData.txt"); - Read CRLF delimited lines from the input stream.
LineReader lineReader = new LineReader(stream);
- Read data from the input stream one line at a time until you reach the end of file flag. Each line is parsed to extract data that is used to construct Country objects.
for(;;){ //Obtain a line of text from the text file String line = new String(lineReader.readLine()); //If we are not at the end of the file, parse the line of text if(!line.equals("EOF")) { int space1 = line.indexOf(" "); String country = line.substring(0,space1); int space2 = line.indexOf(" ",space1+1); String population = line.substring(space1+1,space2); String capital = line.substring(space2+1,line.length()); // Create a new Country object countries.addElement(new Country(country,population,capital)); } else { break; } } // end the for loop return countries; - To add a keyword to the list of selectable text items,
invoke SortedReadableList.doAdd(element).
SortedReadableList.doAdd(((Country)countries.elementAt(i)).getCountryName()) ;
- To update the list of selectable text items, invoke KeywordFilterField.updateList().
_keywordField.updateList();
- To obtain the key word that a BlackBerry device user typed into the KeywordFilterField, invoke KeywordFilterField.getKeyword().
String userTypedWord = _keywordField.getKeyword();
Parent topic: UI components