Open main menu

CDOT Wiki β

Difference between revisions of "Teams Winter 2011/team1/BlackBerry/Add Elements to View Screen"

(Created page with '=== 4. Add Elements to View Screen === 4.1. Create new Class <code>ViewScreen</code> that extends <code>MainScreen</code><br/> 4.2. Set the title: <pre> setTitle("Student Info…')
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
=== 4. Add Elements to View Screen ===
+
=== 5. Add Elements to View Screen ===
4.1. Create new Class <code>ViewScreen</code> that extends <code>MainScreen</code><br/>
+
5.1. Create new Class <code>InfoScreen</code> that extends <code>MainScreen</code> as inner class in MyScreen:<br/>
4.2. Set the title:
+
<source lang="java">
  <pre>
+
  private final static class InfoScreen extends MainScreen {
   setTitle("Student Info");
+
    InfoScreen(Student student) {
  </pre>
+
      //add elements here
4.3.
+
    }
 +
  }
 +
</source>
 +
5.2. Set the title:
 +
  <source lang="java">
 +
   setTitle(student.toString());
 +
</source>
 +
5.3. Add the text field:
 +
<source lang="java">
 +
  BasicEditField emailField = new BasicEditField("email: ",student.getEmail(),50,Field.NON_FOCUSABLE);
 +
  add(emailField);
 +
  </source>
 +
5.4. Format this field:
 +
<source lang="java">
 +
  Border roundedBorder = BorderFactory.createRoundedBorder(new XYEdges(10, 10, 10, 10), Border.STYLE_SOLID);
 +
  Background solidBackground = BackgroundFactory.createSolidBackground(Color.CORAL);
 +
  emailField.setBorder(roundedBorder);
 +
  emailField.setBackground(solidBackground);
 +
</source>
 +
5.5. Override the ,code>close()</code> method:
 +
<source lang="java">
 +
  public void close() {
 +
      Dialog.alert("Quit");
 +
      super.close();
 +
  }
 +
</source>
 +
5.6. Some mehtods inside the <code>MyScreen</code> should be overriden. <br>
 +
In order to show the View screen override the <code>invokeAction()</code> method:
 +
<source lang="java">
 +
  public boolean invokeAction(int action) {     
 +
        if(action == ACTION_INVOKE) {       
 +
            displayInfoScreen();             
 +
            return true;
 +
        }
 +
         
 +
        return super.invokeAction(action);
 +
    }
 +
</source>
 +
5.7. If enter was hit we want to show the view Screen:
 +
<source lang="java">
 +
  protected boolean keyChar(char key, int status, int time) {
 +
        if (key == Characters.ENTER) {
 +
            displayInfoScreen();         
 +
            return true;   
 +
        }
 +
                   
 +
        return super.keyChar(key, status, time);
 +
    } 
 +
</source>
 +
5.8. Override the <code>onSavePrompt()</code> to suppress the save dialog:
 +
<source lang="java">
 +
  public boolean onSavePrompt() {     
 +
        return true;
 +
    }
 +
</source>
 +
5.9. Create the method to push the view screen into the stack:
 +
<source lang="java">
 +
  private void displayInfoScreen(){
 +
        // Retrieve the selected Country and use it to invoke a new InfoScreen     
 +
        Student student = (Student)_keywordFilterField.getSelectedElement();
 +
     
 +
        if(student!= null) {         
 +
            InfoScreen infoScreen = new InfoScreen(student);
 +
            _app.pushScreen(infoScreen);
 +
        }
 +
    }
 +
</source>
 +
5.10. Run the application and click on a student:<br/>
 +
[[Image: BB_view.png | 300px]]

Latest revision as of 12:28, 28 March 2011

5. Add Elements to View Screen

5.1. Create new Class InfoScreen that extends MainScreen as inner class in MyScreen:

  private final static class InfoScreen extends MainScreen {
    InfoScreen(Student student) {
      //add elements here
    }
  }

5.2. Set the title:

  setTitle(student.toString());

5.3. Add the text field:

  BasicEditField emailField = new BasicEditField("email: ",student.getEmail(),50,Field.NON_FOCUSABLE);
  add(emailField);

5.4. Format this field:

  Border roundedBorder = BorderFactory.createRoundedBorder(new XYEdges(10, 10, 10, 10), Border.STYLE_SOLID);
  Background solidBackground = BackgroundFactory.createSolidBackground(Color.CORAL);
  emailField.setBorder(roundedBorder);
  emailField.setBackground(solidBackground);

5.5. Override the ,code>close()</code> method:

  public void close() {
      Dialog.alert("Quit");
      super.close();
   }

5.6. Some mehtods inside the MyScreen should be overriden.
In order to show the View screen override the invokeAction() method:

   public boolean invokeAction(int action) {       
        if(action == ACTION_INVOKE) {        
            displayInfoScreen();               
            return true;
        }
           
        return super.invokeAction(action);
    }

5.7. If enter was hit we want to show the view Screen:

   protected boolean keyChar(char key, int status, int time) {
        if (key == Characters.ENTER) {
            displayInfoScreen();          
            return true;    
        }
                    
        return super.keyChar(key, status, time);
    }

5.8. Override the onSavePrompt() to suppress the save dialog:

   public boolean onSavePrompt() {       
        return true;
    }

5.9. Create the method to push the view screen into the stack:

   private void displayInfoScreen(){
        // Retrieve the selected Country and use it to invoke a new InfoScreen      
        Student student = (Student)_keywordFilterField.getSelectedElement();
       
        if(student!= null) {           
            InfoScreen infoScreen = new InfoScreen(student);
            _app.pushScreen(infoScreen); 
        }
    }

5.10. Run the application and click on a student: