7. Fragments
● A Fragment represents a behavior or a portion
of user interface in an Activity.
● You can think of a fragment as a modular
section of an activity, which has its own
lifecycle, receives its own input events, and
which you can add or remove while the activity
is running (sort of like a "sub activity" that you
can reuse in different activities).
8. Using Fragments
● Fragments are only available 3.0+
● Gingerbread is still on 50%+ of devices
12. The tech side
● MasterFragment
● DetailFragment
● Qualify layouts
– xlarge-land → 2 fragments
– normal → 1 fragment
● MainActivity
– If has a detail fragment, use it
– Or write 2 different activities
14. Common Pitfalls
● Be aware of the Constructor!!
● The Activity may not be always there
– It may have been destroyed
– Or the fragment detached
● There is no communication among fragments
– Do it through the Activity
– Better: Use an interface
15. FragmentManager
● findFragmentById
● findFragmentByTag
● FragmentTransaction
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.mainFragment, MyFragment.newInstance());
ft.commitAllowingStateLoss();
21. Action Bar
● Provide a dedicated space for identifying the
application brand and user location.
● Provide consistent navigation and view
refinement across different applications.
● Make key actions for the activity (such as
"search", "create", "share", etc.) prominent and
accessible to the user in a predictable way.
27. ActionBarSherlock
● Deprecated from Inception
– Same class names, different packages
● Based on the Compat library
● From Android 2.x up
28. Using ABS
● Add ABS as library
● Use the theme for your App
● getActionBar → getSupportActionBar
● Activity → SherlockActivity
● FragmentActivity → SherlockFragmentActivity
● Fragment → SherlockFragment
● And so on...
31. Show me the Code
<com.viewpagerindicator.TitlePageIndicator
android:id="@+id/indicator"
android:padding="10dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
mIndicator = (TitlePageIndicator)findViewById(R.id.indicator);
mIndicator.setViewPager(pager);
32. Navigation Styles
● Top navigation tabs
– For a clear landing page
● Dashboard
– For a set of important options
● Drawer
– Combined with a landing page