Teams Winter 2011/team1/BlackBerry/Add Elements to View Screen
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); } }