Changes

Jump to: navigation, search

Teams Winter 2011/team1/Android/Add Contact

No change in size, 11:14, 28 March 2011
no edit summary
== 67. Add Contact ===== 67.1. Create 'add' layout ===67.1.1. Right click on ''layout -> New -> Android XML File'' .<br/>67.1.2. Enter ''add.xml'' for the file name and check ''Layout'':<br/>67.1.3. Using ''Linear Layout'', create this layout for adding contact information:<br/>
[[Image: add_layout.png | 200px]]<br/>
67.1.4. This is the xml implementation:
<source lang="java">
<?xml version="1.0" encoding="utf-8"?>
</source>
=== 67.2. Create Add Contact Activity ===
This class will be responsible for taking care of adding new contact to the contact list.
67.2.1. Create a new class called ''AddContactActivity.java'' in the same package as the main activity file.
<source lang="java">
package cs.ecl.team1.android;
</source>
67.2.2. Add some fields to save the added information to 'Add Contact' by user.
<source lang="java">
private String firstName;
</source>
67.2.3. On clicking the ''Save Contact'' button, the info from ''EditText''s will be assigned to the corresponding fields.
<source lang="java">
firstName = ((EditText) findViewById(R.id.firstName)).getText().toString();
</source>
67.2.3. The activity will be finished by calling ''finish()'' function from which the ''super'' will be called. In finish(), a new ''Intent'' is created to be able to pass data back to the calling activity.
<source lang="java">
@Override
</source>
=== 67.3. Add Contact Activity to the Android Manifest ===67.3.1. Just add this line to the list of activities in ''AndroidManifest.xml''
<source lang="java">
<activity android:label="Add Contact" android:name="AddContactActivity"></activity>
</source>
=== 67.4. Implement Add Contact in the main activity class ===67.4.1. First step is to create an instance of ''Intent'' to pass the current object to the activity and then start the activity for the ''Add Contact'' when it's selected from the menu items.
<source lang="java">
case R.id.item1:
</source>
67.4.2. In ''startActivityForResult()'', two things need to be checked first, ''resultCode'' and the name of the activity, if these two were fine, the new student with the added values will be added to the list of students, otherwise there will be an alert message displayed to the user.
<source lang="java">
@Override
== 67.5. Add Contact in Action ==67.5.1. Select the 'Add Contact' in the menu<br/>
[[Image: menu.png | 200px]]<br/><br/>
[[Image: add_1.png | 200px]]<br/>
67.5.2. Enter information of the new contact<br/>
[[Image: add_2.png | 200px]]<br/>
67.5.3. The new contact will be appeared in the list of contacts.<br/>
[[Image: added.png | 200px]]<br/>
1
edit

Navigation menu