Changes

Jump to: navigation, search

Teams Winter 2011/team1/BlackBerry/Implement Delete Option

1,514 bytes added, 13:57, 21 March 2011
Created page with '=== 7. Implement Delete Student option === 7.1. In the <code>ViewStudentApp</code> implement <code>DeleteCommandHandler</code> by adding anonymous class: <pre> deleteItem.setC…'
=== 7. Implement Delete Student option ===
7.1. In the <code>ViewStudentApp</code> implement <code>DeleteCommandHandler</code> by adding anonymous class:
<pre>
deleteItem.setCommand(new Command(new CommandHandler(){
public void execute(ReadOnlyCommandMetadata metadata, Object context) {
Student student = (Student) _keywordFilterField.getSelectedElement();
if (student != null) {
String[] selections = {"Yes","Cancel"};
Dialog deleteDialog = new Dialog("Are you sure you want to delete " + student.getName() + "?", selections, null, 0, null);

// Display the dialog and deletes the element from the list
if(deleteDialog.doModal() == 0) {
_studentList.deleteElement(student);
Dialog.alert(student.getName() + " has been deleted!");
}
}
}
}));
</pre>
7.2. Add the <code>deleteElement()</code> method to the <code>StudentList</code> class:
<pre>
void deleteElement(Object element) {
doRemove(element);
}
</pre>
7.3. Run the application, select one student and select "'''Delete Student'''" from the menu:<br/>
[[Image: BB_delete1.png | 300px]]<br/>
7.4. Click "'''Delete Student'''". A dialog box pop-ups asking to confirm the student deletion:<br/>
[[Image: BB_delete2.png | 300px]]<br/>
7.5. Select "'''Yes'''" Option. The dialog window comes up acknowledging that student is deleted:<br/>
[[Image: BB_delete3.png | 300px]]
1
edit

Navigation menu