Guide de développement

Local Navigation

Specify an operation for a selected search result

A UiAction subclass defines an operation that is available to users when they select an item in a list of search results provided by the Unified Search Service. The following steps demonstrate how to create a class named DisplayBookInfo that enables a user to display detailed information about a book in an application that stores information about books.
  1. Import the required classes and interfaces.
    import net.rim.device.api.ui.image.Image;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.unifiedsearch.action.UiAction;
  2. Declare a class that extends UiAction, and create an empty constructor.
    class DisplayBookInfo extends UiAction
    {
    
        DisplayBookInfo ()
        {
    
        }
  3. In the runAction() method, retrieve the SearchableEntity object that the user selected from a search result.
        protected void runAction() 
        {
            BookEntity book = (BookEntity) this.getSearchableEntity();
  4. In runAction(), Create an instance of the DisplayBookScreen class to display the book information. Provide the SearchableEntity object that you retrieved to the new screen object.
            DisplayBookScreen showBook = new DisplayBookScreen(book);
  5. Invoke pushScreen() to make the new screen object visible.
           	UiApplication.getUiApplication().pushScreen(showBook);
        }
  6. Implement the toString() method to provide a description of the operation this class performs.
        public String toString() {
            return "Show book info";
        }
  7. Implement the getIcon() method to associate an icon with this operation. In this task, no icon is provided.
        public Image getIcon() {
            return null;
        }
    }
  8. In the getUiActions() method of your SearchableEntity class, populate the uiActions parameter with your actions like DisplayBookInfo. Change the uiActions array reference using the Arrays object. If you try to change the array without the Arrays object, you will create a local copy of the array. Your local copy is not passed back to the application that requested your UiAction objects. In the following code sample, the ActionTwo and ActionThree classes were added to provide a more complete example.
    public UiAction getUiActions(Object contextObject, UiAction[] uiActions) {
        ActionOne act1 = new ActionOne(this);
        Arrays.add(uiActions, act1);
        Arrays.add(uiActions, new ActionTwo());
        Arrays.add(uiActions, new ActionThree());
  9. Return the UiAction object you want to highlight the menu of actions by default.
        return act1;
    }
    

Was this information helpful? Send us your comments.