Lesson 5: Add data to the table
In this lesson, you add the following controls to the screen:
- a text field in which you can enter a name.
- a menu item to add the name in the text field to the database.
- a list field that displays the names in the table.
You then add code to insert the name in the text field and refresh the list.
- Add the controls to the screen.
- Add the following code before calling the getDataAccess method.
- Add class-level declarations for _nameEditField and _nameListField. Also, define a _addToListMenuItem MenuItem with a run
method (empty for now). These declarations belong next to the declarations of _statusLabel and _da.
- Recompile the application and confirm that it runs.
- Add the following methods and objects to your application:
- A DataAccess method to insert a row into a table
- An object to hold a row of the Names table as an object
- A DataAccess method to read the rows from a table into a Vector of objects
- A method to refresh the contents of the list displayed on the HomeScreen
- A method to add an item to the list on the HomeScreen.
- Add the DataAccess method to insert a row into a table:
- Add the class that holds a row of the Names table. The toString method is used by the ObjectListField control.
- Add the DataAccess method to read the rows from the table into a Vector of objects:
- Add the user interface methods to the HomeScreen class. Following is the method to refresh the list of names:
- Call the refreshNameList method before the end of the HomeScreen constructor so that the list is filled when the application
- Add a HomeScreen method that is used to add a row to the list:
- Call this method from within the run method of the _addToListMenuItem MenuItem (which currently says //TODO):
- Compile and run the application.
Resetting the simulator
If you need to reset the simulator to a clean state, choose Erase Simulator File from the BlackBerry JDE File menu (not the Simulator menu), and erase the items in the submenu. If you reset the simulator this way, you must re-import the UltraLiteJ.cod file before running your application again.