OnClickListener to Process Save Contact Button Events
When the user touches the Save Contact Button
, the saveContactButtonClicked
listener (Fig. 8.39) executes. To save a contact, the user must enter at least the contact’s name. Method onClick
ensures that the length of the name is greater than 0 characters (line 107) and, if so, creates and executes an AsyncTask
(to perform the save operation). Method doInBackground
(lines 113–118) calls saveContact
(Fig. 8.40) to save the contact into the database. Method onPostExecute
(lines 120–131) programmatically hides the keyboard (lines 124–128), then notifies MainActivity
that a contact was saved (line 130). If the nameEditText
is empty, lines 139–153 display a DialogFragment
telling the user that a ...
Get Android™ How to Program, Second Edition 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.