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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access