Я установил KeywordFilterField (спасибо Signare — http://rincethomas.blogspot.in/2012/04/search-field-in-bb.html) и все работает, правда, хотелось бы узнать, как заставить их что-то делать или открывать новый экран при нажатии/клике . Кто-то (также Signare) предложил мне прикрепить идентификатор поля к полю в фокусе, а затем использовать это значение для открытия нового экрана при нажатии, но я не знаю, как это реализовать.
Ниже мой код:
public class IndexScreen extends MainScreen {
KeywordFilterField _keywordFilterField;
CountryList _countryList;
public IndexScreen() {
_countryList = new CountryList();
_countryList.addElement(new Country("Zimbabwe"));
_countryList.addElement(new Country("Argentina"));
_countryList.addElement(new Country("Brazil"));
_countryList.addElement(new Country("Canada"));
_countryList.addElement(new Country("Chile"));
_countryList.addElement(new Country("China"));
_countryList.addElement(new Country("Germany"));
_keywordFilterField = new KeywordFilterField();
_keywordFilterField.setLabel("");
_keywordFilterField.setSourceList(_countryList, _countryList);
setTitle(_keywordFilterField.getKeywordField());
add(_keywordFilterField);
// this.addMenuItem(addElementItem);
// add(this);
}
void addElementToList(Country country) {
_countryList.addElement(country);
_keywordFilterField.updateList();
}
private final MenuItem addElementItem = new MenuItem("Add country", 0, 0) {
public void run() {
_keywordFilterField.setKeyword("");
String[] selections = { "Add", "Cancel" };
Dialog addDialog = new Dialog("Add Country", selections, null, 0,
null);
EditField inputField = new EditField("Country: ", "");
addDialog.add(inputField);
if (addDialog.doModal() == 0) {
addElementToList(new Country(inputField.getText()));
}
}
};
}
class SearchFieldDemoScreen extends MainScreen {
public SearchFieldDemoScreen() {
};
}
class CountryList extends SortedReadableList implements KeywordProvider {
public CountryList() {
super(new CountryListComparator());
}
void addElement(Object element) {
doAdd(element);
}
public String[] getKeywords(Object element) {
if (element instanceof Country) {
return StringUtilities.stringToWords(element.toString());
}
return null;
}
final static class CountryListComparator implements Comparator {
public int compare(Object o1, Object o2) {
if (o1 == null || o2 == null)
throw new IllegalArgumentException(
"Cannot compare null countries");
return o1.toString().compareTo(o2.toString());
}
}
}
class Country {
private String _countryName;
public Country(String countryName) {
_countryName = countryName;
}
public String toString() {
return _countryName;
}
protected boolean navigationClick(int status, int time) {
Field f = getFieldWithFocus();
{
return true;
}
}
private Field getFieldWithFocus() {
// TODO Auto-generated method stub
return null;
}
}
Пожалуйста помоги.