1
edit
Changes
no edit summary
=== 45. Add Elements to View Screen ===45.1. Create new Class <code>ViewScreenInfoScreen</code> that extends <code>MainScreen</code>as inner class in MyScreen:<br/>4.2. Set the title:
<pre>
</pre>
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.3Format 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]]