为什么关键字过滤器无法正常工作?

时间:2014-09-17 16:50:57

标签: java blackberry blackberry-simulator

 */
public final class MyScreen extends MainScreen
{
    private KeywordFilterField _keywordFilterField;
    private mypackage.StationListSortclass _stationListSort;
    private VerticalFieldManager stationListPopUpManager;
    private PopupScreen stationListPopUp;
    public static String[] stationList={"Oakengates-(OKN)",


        };

    /**
     * Creates a new MyScreen object
     */
    public MyScreen()
    {        
        // Set the displayed title of the screen       
        setTitle("MyTitle");
        EditField edit=new EditField("","");
        _keywordFilterField = new KeywordFilterField();
        _stationListSort =new StationListSortclass();
        _keywordFilterField.setSourceList(_stationListSort,_stationListSort );
        _keywordFilterField.setKeywordField(edit); 
        stationListPopUpManager = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL){
            protected void sublayout(int maxWidth, int maxHeight) {
                // TODO Auto-generated method stub
                super.sublayout(maxWidth, maxHeight);
                setExtent(Display.getWidth()/2, Display.getHeight()/2);
            }

        };
        add(edit);
        add(_keywordFilterField);
    }
}
 ----------------------

/**
 * CountryList.java
 * 
 * Copyright © 1998-2009 Research In Motion Ltd.
 * 
 * Note: For the sake of simplicity, this sample application may not leverage
 * resource bundles and resource strings.  However, it is STRONGLY recommended
 * that application developers make use of the localization features available
 * within the BlackBerry development platform to ensure a seamless application
 * experience across a variety of languages and geographies.  For more information
 * on localizing your application, please refer to the BlackBerry Java Development
 * Environment Development Guide associated with this release.
 */ 

package mypackage;


import net.rim.device.api.collection.util.SortedReadableList;
import net.rim.device.api.ui.component.KeywordProvider;
import net.rim.device.api.util.Comparator;
import net.rim.device.api.util.StringUtilities;

public class StationListSortclass extends SortedReadableList implements KeywordProvider
{
    //Constructor
    public StationListSortclass()
    {
        super(new StationListComparator());    
        loadFrom(MyScreen.stationList);
    } 

     /**
      * Adds a new element to the list.
      * @param element The element to be added.
      */

    void addElement(Object element)
    {
        doAdd(element);        
    }    

   /**
    * @see net.rim.device.api.ui.component.KeywordProvider#getKeywords(Object element) 
    */
    public String[] getKeywords( Object element )
    {        


        if(element instanceof String){
        String[] arr= StringUtilities.stringToWords(element.toString());
        return arr;
        }
        return null;

    }  

    /**
     * A Comparator class used for sorting our Country objects by name.
     */
    final static class StationListComparator implements Comparator
    {   
        public int compare(Object o1, Object o2)
        {



            String station1 = (String)o1;
            String station2 = (String)o2;

            if((station1.compareTo(station2)) < 0){
                return -1;
            }
            if((station1.compareTo(station2)) > 0){
                return 1;
            }
            else
            {
                return 0;
            }


        }        
    }    



}

您好 我正在使用黑莓的关键字过滤器。但它工作不正常我不知道为什么它不起作用。 我有名称以及code.i需要搜索代码。但有一段时间它无法搜索。例如当我搜索单词“PAD”或“pad”或另一个例子“zad”时,它会在行顶部进行搜索。但有一段时间它未能到来 例如“wor”为什么当我按下“wor”时它不会出现在顶部?当用户按下“wor”时,我需要在顶部列表中显示worle-(wor)。

0 个答案:

没有答案