1
edit
Changes
→6.2. Create Add Contact Activity
=== 6.2. Create Add Contact Activity ===
This class will be responsible for taking care of adding new contact to the contact list.
6.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;
import android.app.Activity;
public class AddContactActivity extends Activity {
</source>
6.2.2. Add some fields to save the added information to 'Add Contact' by user.
<source lang="java">
private String firstName;
private String lastName;
private String email;
</source>
6.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();
lastName = ((EditText) findViewById(R.id.lastName)).getText().toString();
email = ((EditText) findViewById(R.id.email)).getText().toString();
</source>
6.2.3. The activity will be finished by calling ''finish()'' function from which the ''super'' will be called. In finish(), a new ''Inten'' is created to be able to pass data back to the calling activity.
<source lang="java">
@Override
public void finish() {
Intent i = new Intent();
if (firstName.equals("") && lastName.equals("") && email.equals("")) {
setResult(0);
}
else {
i.putExtra("firstName", firstName);
i.putExtra("lastName", lastName);
i.putExtra("email", email);
setResult(RESULT_OK, i);
}
super.finish();
}
</source>
=== 6.3. Add Contact Activity to the Android Manifest ===
=== 6.4. Implement Add Contact in the main activity class ===