diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-02-13 22:15:10 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-11-10 17:40:55 +0100 |
commit | aa33f187990a0858de0252c96a695d984ba9b924 (patch) | |
tree | 91af28db188e57b41e7e8df19df95d6a0fe82392 /Android/04-TheFragmentClass/FragmentsLab/src/course/labs/fragmentslab/MainActivity.java | |
parent | f14e5dbbdf84a5bc068e3a1cfd104e876dd6da61 (diff) | |
download | coursera-aa33f187990a0858de0252c96a695d984ba9b924.zip coursera-aa33f187990a0858de0252c96a695d984ba9b924.tar.gz |
Android : 04-TheFragmentClass: add
Diffstat (limited to 'Android/04-TheFragmentClass/FragmentsLab/src/course/labs/fragmentslab/MainActivity.java')
-rw-r--r-- | Android/04-TheFragmentClass/FragmentsLab/src/course/labs/fragmentslab/MainActivity.java | 52 |
1 files changed, 52 insertions, 0 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 new file mode 100644 index 0000000..6309bae --- /dev/null +++ b/Android/04-TheFragmentClass/FragmentsLab/src/course/labs/fragmentslab/MainActivity.java @@ -0,0 +1,52 @@ +package course.labs.fragmentslab; + +import android.app.Activity; +import android.app.FragmentTransaction; +import android.os.Bundle; +import android.util.Log; + +public class MainActivity extends Activity implements +FriendsFragment.SelectionListener { + + private static final String TAG = "Lab-Fragments"; + + private FriendsFragment mFriendsFragment; + private FeedFragment mFeedFragment; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main_activity); + // If the layout is single-pane, create the FriendsFragment + // and add it to the Activity + if (!isInTwoPaneMode()) { + mFriendsFragment = new FriendsFragment(); + //TODO 1 - add the FriendsFragment to the fragment_container + } else { + // Otherwise, save a reference to the FeedFragment for later use + mFeedFragment = (FeedFragment) getFragmentManager().findFragmentById(R.id.feed_frag); + } + } + + // If there is no fragment_container ID, then the application is in + // two-pane mode + private boolean isInTwoPaneMode() { + return findViewById(R.id.fragment_container) == null; + } + + // Display selected Twitter feed + public void onItemSelected(int position) { + Log.i(TAG, "Entered onItemSelected(" + position + ")"); + // If there is no FeedFragment instance, then create one + if (mFeedFragment == null) + 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 + getFragmentManager().executePendingTransactions(); + } + // Update Twitter feed display on FriendFragment + mFeedFragment.updateFeedDisplay(position); + } +} |