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

From CDOT Wiki
Jump to: navigation, search
(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…')
 
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:
 
 
  <pre>
 
  <pre>
   setTitle("Student Info");
+
   private final static class InfoScreen extends MainScreen {
 +
    InfoScreen(Student student) {
 +
      //add elements here
 +
    }
 +
  }
 
  </pre>
 
  </pre>
4.3.
+
5.2. Set the title:
 +
<pre>
 +
  setTitle(student.toString());
 +
</pre>
 +
5.3. Add the text field:
 +
<pre>
 +
  BasicEditField emailField = new BasicEditField("email: ",student.getEmail(),50,Field.NON_FOCUSABLE);
 +
  add(emailField);
 +
</pre>
 +
5.4. Format this field:
 +
<pre>
 +
  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);
 +
</pre>
 +
5.5. Override the ,code>close()</code> method:
 +
<pre>
 +
  public void close() {
 +
      Dialog.alert("Quit");
 +
      super.close();
 +
  }
 +
</pre>
 +
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:
 +
<pre>
 +
  public boolean invokeAction(int action) {     
 +
        if(action == ACTION_INVOKE) {       
 +
            displayInfoScreen();             
 +
            return true;
 +
        }
 +
         
 +
        return super.invokeAction(action);
 +
    }
 +
</pre>
 +
5.7. If enter was hit we want to show the view Screen:
 +
<pre>
 +
  protected boolean keyChar(char key, int status, int time) {
 +
        if (key == Characters.ENTER) {
 +
            displayInfoScreen();         
 +
            return true;   
 +
        }
 +
                   
 +
        return super.keyChar(key, status, time);
 +
    } 
 +
</pre>
 +
5.8. Override the <code>onSavePrompt()</code> to suppress the save dialog:
 +
<pre>
 +
  public boolean onSavePrompt() {     
 +
        return true;
 +
    }
 +
</pre>
 +
5.9. Create the method to push the view screen into the stack:
 +
<pre>
 +
  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);
 +
        }
 +
    }
 +
</pre>
 +
5.10. Run the application and click on a student:<br/>
 +
[[Image: BB_view.png | 300px]]

Revision as of 12:27, 21 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:
BB view.png