Changes

Jump to: navigation, search
no edit summary
3.1. Open <code>MyScreen.java</code> class.<br/>
3.2. Create class <code>Student</code> with the following fields:
<presource lang="java">
private String firstName;
private String lastName;
private String email;
</presource
3.3. Add three argument constructor:
<presource lang="java">
public Student(String firstName, String lastName, String email) {
this.firstName = firstName;
this.email = email;
}
</presource
3.4. Add getter method for e-mail and override the <code>toString()</code> from the Object class(it will be used to implement <code>Comparator</code> interface):
<presource lang="java">
public String getEmail() {
return email;
return firstName + " " + lastName;
}
</presource
3.5. Add class that will hold all Student objects and make necessary manipulations:
<presource lang="java">
public class StudentList extends SortedReadableList implements KeywordProvider {
}
}
  </presource>
3.6. The following elements are added to the <code>MyScreen()</code> constructor:<br/>
<presource lang="java">
// A reference to the UiApplication instance for use in this class
_app = app;
// Obtain a reference to the UiApplication's KeywordFilterField
_keywordFilterField = _app.getKeywordFilterField();
</presource>
3.7. Other elements are added inside the <code>ViewStudentApp</code> class. Add necessary private fields:
<presource lang="java">
private KeywordFilterField _keywordFilterField;
private StudentList _studentList;
private Vector _students;
</presource
3.8. Add search field and students list:
<presource lang="java">
MyScreen _mainScreen = new MyScreen(this);
_keywordFilterField = new KeywordFilterField();
_keywordFilterField.setSourceList(_studentList, _studentList);
 
_mainScreen.setTitle(_keywordFilterField.getKeywordField());
_mainScreen.add(_keywordFilterField);
</presource>
3.89. Add background to the ''keywordFilterField'': <source lang="java"> // Attempt to load a bitmap background try { Background bitmapBackground = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("background.png"), Background.POSITION_X_CENTER, Background.POSITION_Y_CENTER, Background.REPEAT_BOTH); _keywordFilterField.setBackground(bitmapBackground);   } catch (final IllegalArgumentException e) { UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { Dialog.alert(e.toString()); } }); }</source> 3.10. Add inner class for custom search field: <presource lang="java">
final static class CustomKeywordField extends BasicEditField {
// Constructor
}
}
</presource> 3.911. Add the method that creates lists of students: <presource lang="java">
private Vector getFromList() {
Vector students = new Vector();
_keywordFilterField.updateList();
}
</presource> 3.1012. Add the method to access the <code>KeywordFilterField</code> object: <presource lang="java">
KeywordFilterField getKeywordFilterField() {
return _keywordFilterField;
}
</presource> 3.1113. Run the application:<br/>
[[Image: BB_mainscreen.png | 300px]]<br/>
3.1214. Type the desired student name in the search field:<br/>
[[Image: BB_search.png | 300px]]
1
edit

Navigation menu