关于程序员:COMP-208

5次阅读

共计 3861 个字符,预计需要花费 10 分钟才能阅读完成。

COMP 208, Assignment 1
Milestone 1
Outline
Create an Android application that manages contacts using an SQLite database. The application should allow the user to add new contacts, list all contacts, and display contact details.
Step 1 (Contacts Model)
1.Create a new Android application project.
2.Create a Contact class that stores the following information:
a.Contact id,
b.First and last name,
c.Phone,
d.Email,
e.Contact Type (friend, family, business, etc.)
3.Create a hardcoded array of Contact objects. Initialize the Contact objects with sample data.
4.Create a layout that displays the information stored in a single Contact object. Make use of style classes and string resources in your layout. (Note: issues icon in the Design Editor should indicate no
5.Add a MatrixCursor with columns that correspond to the fields in the Contact class. Populate the matrix cursor with the data stored in the contacts array.
6.Add First, Last, Prev, and Next buttons to the layout. Add click handlers to the buttons to allow the user to display contact information by navigating through the data held by the matrix cursor.
Step 2 (SQLite Database)
1.Create a DBContract class that defines the structure of a contacts database that contains a contact table. The columns of the table should match the fields of the Contact class.
2.Create a DBHelper class that defines methods to create the contacts database, insert records into the contact table, and select records from the contact table. (Update and delete methods are not required for this milestone.)
3.Add code to populate the contact table with the data held by the matrix cursor created in Milestone 1.
4.Modify the code in the click handlers so that they obtain contact data by querying the contacts database.
5.Document your code (using JavaDoc comments and annotations).
6.Test your application.
Hand In
At the end of the lab, zip your entire project into a file named YourLastName.zip. Copy the zip file to the drop box folder named COMP 208 A1 M1. (Hand in your project even if you have not finished this milestone.)
References:
All parts of this assignment have been covered in class or in previous labs.
A sample database project (DBDemo2) is available in the COMP 208 academic share folder. (Note: you may not be able to build and run this project without significant downloads to the ADK. Use this project as a code reference only.)
You may also have to use JavaDoc documentation for some of the classes (e.g. MatrixCursor).

Milestone 2
Outline
Add a 2nd Activity to the Contacts application. The layout for this activity should include a ListView that displays a scrolling list of the names of the contacts stored in the contacts database. When the user clicks on a contact name the contact details are displayed.

Step 3 (Create New Activity and Layout)
1.Create a new Activity by right clicking on the java node (in the Projects window), select Activity, then select Empty Activity.
2.In the Configure Activity dialog, set the Activity name to ContactListActivity, set the layout file name to contactlist_layout, and check the Launcher Activity checkbox. Finish.
3.Refactor the MainActivity name to ContactDetailsActivity.
4.Open the AndroidManifest.xml file and verify that the activity node named ContactListActivity includes an intent-filter node that sets the intent action to LAUNCHER. Since this activity will now become the new main activity, remove the corresponding intent filter from the .ContactDetailsActivity node.
5.Open the contactlist_layout and add a ListView to the layout. Add a Details button below the ListView.
(ListView is found under the Legacy section of the Palette window.) Set the constraints of the list view so that it fills the screen.

Step 4 (Display List of Contact Names)
Follow the code from previous labs to add code to connect the list view to the contact data in the database.
1.Add a click hander to the Details button to navigate to the contact details page.
2.Define a layout with components that will display a single contact’s name and phone number.
3.In the DBHelper class, add a function that queries the contacts database and returns the contact id, first name and last name for all contacts.
4.Note: you will have to call getReadableDatabase() rather than getWritableDatabase().
5.Create a SimpleCursorAdapter that connects the data returned from the query to the ListView.

Hand In
At the end of the lab, zip your entire project into a file named YourLastName.zip. Copy the zip file to the drop box folder named COMP 208 A1 M2. (Hand in your project even if you have not finished this milestone.)

正文完
 0