MainActivity Method displayAddEditFragment

Method displayAddEditFragment (Fig. 8.20) receives a View’s resource ID specifying where to attach the AddEditFragment and a Bundle of key–value pairs. If the second argument is null, a new contact is being added; otherwise, the Bundle contains the data to display in the AddEditFragment for editing. Line 105 creates the AddEditFragment. If the Bundle argument is not null, line 108 uses it to set the Fragment’s arguments. Lines 111–115 then create the FragmentTransaction, replace the contents of the View with the specified resource ID, add the Fragment to the back stack and commit the transaction.

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.