Created
March 5, 2014 22:12
-
-
Save csdear/fd8c49b2e3096199af91 to your computer and use it in GitHub Desktop.
Fragments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.app.FragmentManager; | |
| import android.app.FragmentTransaction | |
| private FragmentManager mFragmentManager; | |
| private FriendsFragment mFriendsFragment; | |
| //onCreate | |
| mFragmentManager = getFragmentManager(); | |
| // Adding fragment to activity | |
| private void add<<FragName>>Fragment() { | |
| <<fragFieldName>> = new <<supportinfragmentClassName>>(); | |
| <<fragFieldName>>.setArguments(getIntent().getExtras()); | |
| FragmentTransaction transaction = mFragmentManager.beginTransaction(); | |
| transaction.add(R.id.fragment_container, <<fragFieldName>>); | |
| transaction.commit(); | |
| } | |
| // a fragment container xml | |
| <?xml version="1.0" encoding="utf-8"?> | |
| <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| android:id="@+id/fragment_container" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" /> | |
| ===================================================== | |
| //Feed Fragments -- see CodeRepoLocal - Notifications | |
| private int mFeedSelected = UNSELECTED; | |
| private FeedFragment mFeedFragment; | |
| [...] | |
| // onItemSelected | |
| @Override | |
| public void onItemSelected(int position) { | |
| <<fieldSelectedItem>> = position; | |
| mFeedFragment = addFeedFragment(); | |
| //Checks when last update was... | |
| if (mIsFresh) { | |
| updateFeed(); | |
| } | |
| } | |
| //addFeedFragment () | |
| private FeedFragment addFeedFragment() { | |
| FeedFragment feedFragment; | |
| feedFragment = new FeedFragment(); | |
| FragmentTransaction transaction = mFragmentManager.beginTransaction(); | |
| transaction.replace(R.id.fragment_container, feedFragment); | |
| transaction.addToBackStack(null); | |
| transaction.commit(); | |
| mFragmentManager.executePendingTransactions(); | |
| return feedFragment; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment