String choiceItems[] = {"Option one","Option two", "Option three"};
mainScreen.add(new ObjectChoiceField("Select an option:", choiceItems));
Create a text list that can be filtered
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. A word that a BlackBerry® device user enters into the text input field filters the elements in the list.
For more information about using the
KeywordFilterField
class, see the
KeywordFilterFieldDemo
sample, included
with the BlackBerry® Java® Development Environment version 4.3.1.
1.
Import the following classes:
•
net.rim.device.api.ui.component.KeywordFilterField
•
net.rim.device.api.collection.util.SortedReadableList
•
net.rim.device.api.collection.util.SortedReadableList
•
java.util.Vector
•
java.io.InputStream
•
net.rim.device.api.io.LineReader
•
java.lang.String
2.
Import the
net.rim.device.api.ui.component.KeywordProvider
interface.
3.
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;
4.
To create a list of selectable text items, populate a vector with data from a text file.
_countries = getDataFromFile();
5.
Create an instance of a class that extends the
SortedReadableList
class.
_CountryList = new CountryList(StringComparator.getInstance
(true),_countries);
6.
To specify the elements of the list, create a new instance of a
KeywordFilterField
object.
_keywordField = new KeywordFilterField();
7.
Invoke
KeywordFilterField.setList()
.
_keywordField.setList(_CountryList, _CountryList);
8.
Set a label for the input field of the
KeywordFilterFIeld
.
_keywordField.setLabel("Search: ");
9.
Create the main screen of the application and add a
KeywordFilterField
to the main screen.
Development Guide
UI components
17