Difference between revisions of "Teams Winter 2011/team1/BlackBerry/Add Menu to the Application"

From CDOT Wiki
Jump to: navigation, search
(7. Add Menu to the Application)
Line 3: Line 3:
 
7.2 Add view, add, edit and delete student options to the menu and set commands to execute:
 
7.2 Add view, add, edit and delete student options to the menu and set commands to execute:
 
  <pre>
 
  <pre>
       MyScreen _mainScreen = new MyScreen();
+
       MyScreen _mainScreen = new MyScreen(this);      
        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);
+
         MenuItem addItem = new MenuItem(new StringProvider("Add Student"), 200, 2);
 
         adds.setCommand(new Command(new AddCommandHandler()));
 
         adds.setCommand(new Command(new AddCommandHandler()));
         _mainScreen.addMenuItem(adds);
+
         _mainScreen.addMenuItem(addItem);
 
        
 
        
         MenuItem edit = new MenuItem(new StringProvider("Edit Student"), 300, 3);
+
         MenuItem editItem = new MenuItem(new StringProvider("Edit Student"), 300, 3);
 
         edit.setCommand(new Command(new EditCommandHandler()));
 
         edit.setCommand(new Command(new EditCommandHandler()));
         _mainScreen.addMenuItem(edit);
+
         _mainScreen.addMenuItem(editItem);
 
        
 
        
 
         MenuItem delete = new MenuItem(new StringProvider("Delete Student"), 400, 4);
 
         MenuItem delete = new MenuItem(new StringProvider("Delete Student"), 400, 4);
 
         delete.setCommand(new Command(new DeleteCommandHandler()));
 
         delete.setCommand(new Command(new DeleteCommandHandler()));
         _mainScreen.addMenuItem(delete);
+
         _mainScreen.addMenuItem(deleteItem);
 
        
 
        
 
         pushScreen(_mainScreen);
 
         pushScreen(_mainScreen);
Line 24: Line 21:
 
7.3. Create inner classes to execute all commands:
 
7.3. Create inner classes to execute all commands:
 
  <pre>
 
  <pre>
  class ViewCommandHandler extends CommandHandler
+
 
    {
 
        public void execute(ReadOnlyCommandMetadata metadata, Object context){
 
            Dialog.alert("View was selected");
 
        }
 
    }
 
 
     class AddCommandHandler extends CommandHandler
 
     class AddCommandHandler extends CommandHandler
 
     {
 
     {
Line 49: Line 41:
 
     }
 
     }
 
  </pre>
 
  </pre>
7.4.
+
7.4. Run the application. Click on the menu you should see the following:
 +
[[Image: BB_Menu.png | 300px]]

Revision as of 11:28, 21 March 2011

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(this);       
       
        MenuItem addItem = new MenuItem(new StringProvider("Add Student"), 200, 2);
        adds.setCommand(new Command(new AddCommandHandler()));
        _mainScreen.addMenuItem(addItem);
       
        MenuItem editItem = new MenuItem(new StringProvider("Edit Student"), 300, 3);
        edit.setCommand(new Command(new EditCommandHandler()));
        _mainScreen.addMenuItem(editItem);
       
        MenuItem delete = new MenuItem(new StringProvider("Delete Student"), 400, 4);
        delete.setCommand(new Command(new DeleteCommandHandler()));
        _mainScreen.addMenuItem(deleteItem);
       
        pushScreen(_mainScreen);
 

7.3. Create inner classes to execute all commands:

  
    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. Run the application. Click on the menu you should see the following: BB Menu.png