From 36280db96fe3e135b64e85365b346d387b5dba18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 13 Feb 2014 22:15:31 +0100 Subject: Android : 04-TheFragmentClass: implement --- .../src/course/labs/fragmentslab/MainActivity.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Android/04-TheFragmentClass/FragmentsLab/src/course/labs/fragmentslab/MainActivity.java b/Android/04-TheFragmentClass/FragmentsLab/src/course/labs/fragmentslab/MainActivity.java index 6309bae..9fa845e 100644 --- a/Android/04-TheFragmentClass/FragmentsLab/src/course/labs/fragmentslab/MainActivity.java +++ b/Android/04-TheFragmentClass/FragmentsLab/src/course/labs/fragmentslab/MainActivity.java @@ -21,7 +21,9 @@ FriendsFragment.SelectionListener { // and add it to the Activity if (!isInTwoPaneMode()) { mFriendsFragment = new FriendsFragment(); - //TODO 1 - add the FriendsFragment to the fragment_container + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.add(R.id.fragment_container, mFriendsFragment); + fragmentTransaction.commit(); } else { // Otherwise, save a reference to the FeedFragment for later use mFeedFragment = (FeedFragment) getFragmentManager().findFragmentById(R.id.feed_frag); @@ -42,8 +44,10 @@ FriendsFragment.SelectionListener { mFeedFragment = new FeedFragment(); // If in single-pane mode, replace single visible Fragment if (!isInTwoPaneMode()) { - //TODO 2 - replace the fragment_container with the FeedFragment - // execute transaction now + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.fragment_container, mFeedFragment); + fragmentTransaction.addToBackStack(null); + fragmentTransaction.commit(); getFragmentManager().executePendingTransactions(); } // Update Twitter feed display on FriendFragment -- cgit v1.1-2-g2b99