Coding the Add Button

Coding the Add button is just reusing code that you used before (Listing 6.17).

Listing 6.17 initAddContactButton() Method

private void initAddContactButton() {    Button newContact = (Button) findViewById(R.id.buttonAdd);    newContact.setOnClickListener(new OnClickListener() {        public void onClick(View v) {            Intent intent = new Intent(ContactListActivity.this, ContactActivity.class);            startActivity(intent);        }    });}

Remember to call the initAddContactButton() method in the onCreate method.

Get Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.