3. 1. Whats the Problem?
2. What Are Fragments?
3. How Do I Use Fragments
4. Look at Code!
5. What about Backwards
Compatibility?
Things We’ll Talk About
11. ❖ User Interface “modules”
❖ Can share Fragments across different
activity
❖ On Activity can have many
fragments
❖ Different screen sizes have different
layouts
What are Fragments?
12.
13. ❖ Android 3.0 or Higher (well, sort of/not really)
❖ Subclass the Fragment base class
❖ They can load Layout files / Create it’s UI similar to an Activity
❖ There are specialized fragments
❖ Fragments have a lifecycle, just like Activities
Fragment Basics
17. Fragments Need Help
❖ Must be hosted in an Activity
❖ Activities are Not Directly Aware of
their Fragments
❖ Fragments are aware of their host
Activity
❖ Fragments are not aware of other
Fragments
❖ FragmentManager is the middle man
19. Adding a Static Fragment
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
class="net.opgenorth.shakespeare.TitlesFragment"
android:id="@+id/titles_fragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
20. Adding a Dynamic Fragment
// Make new fragment to show this selection.
DetailsFragment details = new DetailsFragment();
// Execute a transaction, adding the fragment to the FrameLayout.
FragmentTransaction ft = FragmentManager.beginTransaction();
ft.add(Resource.Id.details, details, "details_fragment");
ft.commit();
23. Android Support Libraries
❖ A set of code libraries that provide
backwards compatibility and features
to older API levels
24. ❖ Building a Dynamic UI with Fragments - http://developer.android.com/
training/basics/fragments/index.html
❖ Support Libraries - http://developer.android.com/tools/support-library/
index.html
Links / References