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
Contributor
Posts: 42
Registered: ‎10-23-2011
My Device: curve 8520
My Carrier: george najem

PLEASE HELP ! keyword filter field will not appear

I am trying to implement a keywordfilterfield in the second screen of this app (Handler Screen)

 

Does anyone know why it wont appear. here is the following code

/*
 * ActiveTextFieldsDemo.java
 *
 * Copyright © 1998-2011 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 com.rim.samples.device.activetextfieldsdemo;


import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.blackberry.api.stringpattern.*;
import net.rim.blackberry.api.menuitem.*; 

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.collection.ReadableList;
import net.rim.device.api.util.Comparator;
import java.util.*;
import net.rim.device.api.collection.util.*; 
import net.rim.device.api.util.StringUtilities;

 /** 
  * Sample to demonstrate functionality of active text fields and
  * PatternRepository API. Upon startup of device a regular expression
  * is registered with the String Pattern Repository.  If pattern is
  * encountered in an active text field in a device application, the
  * text will be underlined and specified context menu items will be
  * available. If a menu item is invoked, this application will be 
  * invoked and a handler screen will display information corresponding
  * to the matched pattern. This application also provides a GUI demo
  * screen with an ActiveAutoTextEditField.
  */
public final class ActiveTextFieldsDemo extends UiApplication
{
    private static ApplicationMenuItem[] _menuItems = new ApplicationMenuItem[1];
    private static RichTextField _trackingNumber; 
    static KeywordFilterField _keywordFilterField;    
    static FoodList _foodList;
    
    /**
     * Entry point for application 
     * @param args Command line arguments
     */  
    public static void main(String[] args)
    {        
        if(args != null && args.length > 0)
        {
            // When device starts we want to register our regular expression in 
            // the PatternRepository.
            if (args[0].equals("autostartup"))
            {
                // Assign menu items to ApplicationMenuItem array.
                _menuItems[0] = statusItem;
                      
                
              /*  
              * First we create an ApplicationDescriptor referencing this
              * application. Then we register a regular expression and associate
              * our ApplicationDescriptor along with our menu items. When a nine
              * digit number is typed in an active text field the matched pattern
              * will be highlighted and the additional menu items will be
              * available. The menu items will launch an instance of this
              * appplication when invoked.
              */ 
                ApplicationDescriptor appDesc = new ApplicationDescriptor(ApplicationDescriptor.currentApplicationDescriptor(),"Active Text Fields",new String[]{"pattern-recognized"});
                PatternRepository.addPattern(appDesc,"[0-9]{9}",PatternRepository.PATTERN_TYPE_REGULAR_EXPRESSION,_menuItems);           
            }
            
            // This block will execute when one of our application menu items
            // is invoked.  
            else if(args[0].equals("pattern-recognized"))
            {
                // We don't want to launch the demo version of this app,
                // we just want to throw up a screen displaying status or
                // location information.  Therefore we pass false into
                // the constructor. 
                ActiveTextFieldsDemo app = new ActiveTextFieldsDemo(false);                       
                app.enterEventDispatcher();
            }
        }
        
        // This block will execute if the user starts this application from
        // the desktop.
        else 
        { 
            // We want to launch the demo version of this application, pass true
            // to constructor.
            ActiveTextFieldsDemo app = new ActiveTextFieldsDemo(true);           
            app.enterEventDispatcher();
        } 
    }    
    
    
    /**
    * Constructs a new ActiveTextFieldsDemo object
    * @param isDemoApp Flag to indicate whether application was invoked explicitly from the desktop or by invoking a menu item
    */
    public ActiveTextFieldsDemo(boolean isDemoApp)
    {        
        // Display a MainScreen that simply allows user to type a 9 digit number
        // into an ActiveAutoTextEditField to demonstrate the pattern recognition
        // functionality. 
        if(isDemoApp)
        {
            ActiveTextFieldsScreen demoScreen = new ActiveTextFieldsScreen();
            pushScreen(demoScreen);        
        }
        
       // If the user invoked one of our application menu items we want to
       // display a MainScreen providing tracking information. 
        else
        {
            
            HandlerScreen handlerScreen = new HandlerScreen();
            pushScreen(handlerScreen);
            
            // When this application is launched we want to make it visible by
            // bringing it to the foreground. 
            ApplicationManager.getApplicationManager().requestForeground(getProcessId());
        }
    }
    
    // Anonymous inner classes to extend abstract class ApplicationMenuItem.
    //  The run() method will execute upon selection of the menu item.  In a
    // real world situation the application would send the highlighted
    // transaction number back to a server and retrieve the status and location
    // information.     
    private static ApplicationMenuItem statusItem = new ApplicationMenuItem(0x230010)
    {
        
       /**
        * Sets the label and text in the display fields of the handler screen
        * 
        * @param context The String representation of the context object is displayed
        */  
        public Object run(Object context)
        {
            _trackingNumber.setLabel("Status for tracking No: ");
            _trackingNumber.setText(context.toString());
              
            _foodList = new FoodList();
            
            _foodList.addElement(new Food("George A- la mode"));
            _foodList.addElement(new Food("Pizza"));
            
            _keywordFilterField = new KeywordFilterField();
            _keywordFilterField.setLabel("");
            _keywordFilterField.setSourceList(_foodList, _foodList);
            
            SearchField screen = new SearchField();
            screen.setTitle(_keywordFilterField.getKeywordField());
            screen.add(_keywordFilterField);
            
            
            
            return null;
        }
        
        public String toString()
        {
            return "Status";   
        }
    };
    

    
    /**
    * The screen that is displayed when one of our application menu items
    * is invoked.
    */
   public static final class HandlerScreen extends MainScreen 
    {
       
       /**
        * Creates a new HandlerScreen object
        */
	   
	   
       public HandlerScreen()
       {            
    	  
           
    	   
           // These are the fields that will display the tracking information
           _trackingNumber = new RichTextField("rtrt");            
           add(_trackingNumber);
                               
       }  
       
       
    }   
   
    void addElementToList(Food food)
    {       
         _foodList.addElement(food);
        _keywordFilterField.updateList();       
    }   
    
  
}

class SearchField extends MainScreen
{
    public SearchField(){};
} 

class FoodList extends SortedReadableList implements KeywordProvider
{
    public FoodList()
    {
        super(new FoodListComparator());        
    } 
   
    void addElement(Object element)
    {
        doAdd(element);        
    }
    
    public String[] getKeywords(Object element)
    {
        if(element instanceof Food)
        {
            return StringUtilities.stringToWords(element.toString());
        }
        return null;
    }

    final static class FoodListComparator 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 Food
{
    private String _foodName;
    
    public Food(String foodName)
    {
        _foodName = foodName;        
    }
    
    public String toString()
    {
        return _foodName;
    }  
    
    
    
}





/**
* The screen for the demo version of this application
*/
final class ActiveTextFieldsScreen extends MainScreen 
{    
    /**
     * Creates a new ActiveTextFieldsScreen object
     */    
    ActiveTextFieldsScreen()
    {        
        // Set the screen title
        setTitle("Active Text Fields Demo");
        
        // Add instructions
        add(new RichTextField("Type a nine digit number in the Transaction No. field. Pattern will be hyperlinked and status and location menu items will be available.\n",Field.NON_FOCUSABLE));
                    
        // Add an ActiveAutoTextEditField
        ActiveAutoTextEditField activeField = new ActiveAutoTextEditField("Transaction No: ", null);
        add(activeField);
        activeField.setFocus();  
        
        
        
    }
    
    /**
     * Prevents the save dialog from being displayed
     * 
     * @see net.rim.device.api.ui.container.MainScreen#onSavePrompt()
     */
    public boolean onSavePrompt()
    {
        return true;
    }                  
}  

 

Contributor
Posts: 42
Registered: ‎10-23-2011
My Device: curve 8520
My Carrier: george najem

Re: PLEASE HELP ! keyword filter field will not appear

some body please replyy~!!!!