Teams Winter 2011/team1/BlackBerry/Add Menu to the Application

From CDOT Wiki
Revision as of 15:53, 17 March 2011 by Azea (talk | contribs) (7. Add Menu to the Application)
Jump to: navigation, search

7. Add Menu to the Application

7.1. Open MyApp class and add menu items inside the constructor.
7.2 Add view, add, edit and delete student options to the menu and set commands to execute:

      MyScreen _mainScreen = new MyScreen();
        MenuItem view = new MenuItem(new StringProvider("View Student"), 100, 1);
        view.setCommand(new Command(new ViewCommandHandler()));
        _mainScreen.addMenuItem(view);
       
        MenuItem adds = new MenuItem(new StringProvider("Add Student"), 200, 2);
        adds.setCommand(new Command(new AddCommandHandler()));
        _mainScreen.addMenuItem(adds);
       
        MenuItem edit = new MenuItem(new StringProvider("Edit Student"), 300, 3);
        edit.setCommand(new Command(new EditCommandHandler()));
        _mainScreen.addMenuItem(edit);
       
        MenuItem delete = new MenuItem(new StringProvider("Delete Student"), 400, 4);
        delete.setCommand(new Command(new DeleteCommandHandler()));
        _mainScreen.addMenuItem(delete);
       
        pushScreen(_mainScreen);
 

7.3. Create inner classes to execute all commands:

   class ViewCommandHandler extends CommandHandler
    {
        public void execute(ReadOnlyCommandMetadata metadata, Object context){
            Dialog.alert("View was selected");
        }
    }
    class AddCommandHandler extends CommandHandler
    {
        public void execute(ReadOnlyCommandMetadata metadata, Object context){
            Dialog.alert("Add was selected");
        }
    }
    class EditCommandHandler extends CommandHandler
    {
        public void execute(ReadOnlyCommandMetadata metadata, Object context){
            Dialog.alert("Edit was selected");
        }
    }
    class DeleteCommandHandler extends CommandHandler
    {
        public void execute(ReadOnlyCommandMetadata metadata, Object context){
            Dialog.alert("Delete was selected");
        }
    }
 

7.4.