1
edit
Changes
→11.7 Modify StudentsList Class to use SQLiteManager
11.7.1 Load list<br/>
As noticed above, the constructor then passes those objects to a new SQLiteManager object and gets students from the manager to load the list with. Then it closes the database.<source lang="java"br/>
11.7.2 Add Student<br/>
Now modify the addElement method:
<source lang="java">
/** * Adds a new element to the list. * @param element The element to be added. */ void addElement(Object element) { Student student = (Student) element; SQLManager sqlManager = new SQLManager(db, uri); sqlManager.addStudent(student.getFirstname(), student.getLastName(), student.getEmail(), student.getAddress()); doAdd(element); SQLManager.closeDB(); }
</source>
11.7.3 Edit Student<br/>
And editElement method:
<source lang="java">
// added for Update: void updateElement(Object oldElement, Object newElement){ Student student = (Student) newElement; SQLManager sqlManager = new SQLManager(db, uri); sqlManager.updateStudent(student.getId(), student.getFirstname(), student.getLastName(), student.getEmail(), student.getAddress()); doUpdate(oldElement,newElement); SQLManager.closeDB(); }
</source>