Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 84
Registered: ‎01-10-2013
My Device: Bold 9900
My Carrier: China Unicom
Accepted Solution

A strange problem of KeywordFilterField

[ Edited ]
package mypackage;

import javax.microedition.lcdui.Font;
import net.rim.device.api.collection.util.SortedReadableList;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.util.Comparator;
import net.rim.device.api.util.StringUtilities;

public final class KeywordSearchScreen extends MainScreen
{
     public static final String[] VendorID={"-1","0","1"};
     public static final String[] VendorName={"非正常销售、非正常工作状态手机","EDT工程机","DVT测试机"};
KeywordFilterField _keywordFilterField; CountryList _countryList; static final int ListRowHeightOffset=13; public KeywordSearchScreen() { setTitle("Keyword Search"); _countryList = new CountryList(); for(int i=0; i<=VendorID.length-1; i++) { _countryList.addElement(new Country(VendorID[i] + ": " + VendorName[i])); } _keywordFilterField = new KeywordFilterField(); _keywordFilterField.setSourceList(_countryList, _countryList); setTitle("View all vendors"); add(_keywordFilterField); } } 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; } }

 

This is my code by using KeywordFilterField class, in the begining it was very good to show the UI, but now, i just got an UI that a KeywordFilterField without TextFiled, only shown a list for me, and the search function is correctly, i was so sad, anybody can help?

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: A strange problem of KeywordFilterField

I am not 100% clear on what you are asking, but try the following:

 

Between these two lines:

setTitle("View all vendors");
add(_keywordFilterField);

 

insert the following line:

add(_keywordFilterField.getKeywordField());

 

The three lines should now look like:

 

setTitle("View all vendors");
add(_keywordFilterField.getKeywordField());
add(_keywordFilterField);

Developer
Posts: 84
Registered: ‎01-10-2013
My Device: Bold 9900
My Carrier: China Unicom

Re: A strange problem of KeywordFilterField

thanks guy, it was really my mistake. i was used setTitle(String) to instead of setTitle(getKeywordField()), so i got this trouble.

thanks again!