Fragments and the ActionBar


Welcome to final part of this review of the Pluralsight course Improving User Interface Design with Android Fragments by Jim Wilson.

Jim has over 30 years of software engineering experience, with the past 15 years heavily focused on creating mobile device and location-based solutions. He has co-founded multiple software-related startups and has served in a consulting role at several more.

After nearly a decade as a Microsoft Device Application Development MVP, Jim now focuses on developing Android and iOS device applications. Jim’s passion is mentoring software developers. He blogs at

Improving User Interface Design with Android Fragments is the 8th course in the Pluralsight learning path for Android, and this month I am reviewing every course in this learning path.

Also in this series:

Part 1 – Fragment Basics

Fragments and the ActionBar


Jim introduces the ActionBar as one of the most important Android concepts.

For a more in depth look at the ActionBar see his course Improving User Interaction with the ActionBar.

The ActionBar has a close relationship with Fragments.

Fragment-specific menu options

Fragments can be used to add menu items onto the ActionBar.

This allows per-fragment specialization of the menu.

The Fragment menu options can be handled either by the Activity, or by the Fragment.

Jim says in most cases we will want to do this in the Fragment, so that we have specialization.

We are warned never to use the android:onClick attribute in our menu layout resources for our Fragments, because it always routes to the Activity.

Demo: Fragment-specific menu options

We begin with a simple app with 4 menu options:

  • “Android 4.0 Course”
  • “Android Intents Course”
  • “List”
  • “Tabbed”

We implement click handler methods for the first two of these:

  • onAndroid40CourseFragmentClick
  • onIntentsCourseFragmentClick

These create a FragmentTransaction and replace the existing fragment.

We see that the Android 4.0 selection gives the app a green background and the Android Intents selection gives the app a blue background.

We also build out a big switch statement in, setting handled to true in each case.

ActionBar and Fragment navigation

The ActionBar provides rich navigation behavior, including List navigation and Tabbed navigation.

List navigation

List navigation provides the user with a drop-down list of screens, and the list is created as a SpinnerAdapter.

We see a screenshot of an example ActionBar with a drop-down list of email addresses. Each list item takes us to a new screen, and each screen is implemented as a fragment.

We implement this with ActionBar.OnNavigationListener interface.

Demo: List navigation

We begin in and implement the ActionBar.OnNavigationListener interface and it’s onNavigationItemSelected method with a simple switch statement and a FragmentTransaction.

Jim also explains the code we need in onCreate.

We see that we can switch screens based on the list in our ActionBar.

Tabbed navigation

Tabbed navigation is a 3 phase process and Jim explains what these are.

The ActionBar.TabListener handles each tab’s interaction.

The ActionBar.TabListener methods described are:

  • onTabSelected
  • onTabUnselected
  • onTabReselected

Demo: Tabbed navigation

We begin this final lesson looking at We implement the ActionBar.TabListener interface and its 3 methods.

Jim explains his createTab helper method and builds out the onCreate method.

By the end of this lesson we have a bar with two tabs: “What’s New in Android 4.0” and “Android Intents”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s