MainActivity Method displayContact

Method displayContact (Fig. 8.18) creates the DetailsFragment that displays the selected contact and uses a FragmentTransaction to attach it to the GUI. You can pass arguments to a Fragment by placing them in a Bundle of key–value pairs—we do this to pass the selected contact’s rowID so that the DetailsFragment knows which contact to get from the database. Line 80 creates the Bundle. Line 81 calls its putLong method to store a key–value pair containing the ROW_ID (a String) as the key and the rowID (a long) as the value. Line 82 passes the Bundle to the Fragment’s setArguments method—the Fragment can then extract the information from the Bundle (as you’ll see in Section 8.8). Lines 85–86 get a FragmentTransaction ...

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.