Search code examples
androidandroid-activityactionbarsherlockfragment

Android - SherlockActionBar - What is benefit of using SherlockFragments?


I get the benefits of the SherlockActionBar 100%.

What is the benefit of SherlockFragments though? You have your main Activity /FragmentActivity which is hosting all of your other fragments etc. and extends SherlockActivity / SherlockFragmentActivity.

If you can get reference to your parent Activity in the onAttach(Activity parentActivity) Fragment method, and use methods like parentActivity.getActionBar().setTitle(title) etc. Why would you choose to make those Fragments Sherlock fragments?

Quite new to this Sherlock stuff and any insight would be very appreciated.

Cheers


Solution

  • Why would you choose to make those Fragments Sherlock fragments?

    So you can use setHasOptionsMenu(), onCreateOptionsMenu(), and onOptionsItemSelected() in the fragment. As fragments come and go from the screen, Android will automatically add and remove those fragments' action bar items from the action bar.