Google Groups

Re: [android-developers] Using v4 Fragments with v11 ActionBar tabs


Mark Murphy Apr 19, 2011 8:18 AM
Posted in group: Android Developers
On Tue, Apr 19, 2011 at 11:10 AM, Dave Johnston <joh...@gmail.com> wrote:
> I'm having trouble implementing ActionBar tabs whilst also using
> backward-compatible Fragments (with the compatibility package).
>
> The main issue being that ActionBar.TabListener expects
> android.app.Fragment, and my Fragment classes inherit from
> android.support.v4.app.Fragment. Therefore I can't use my Fragments
> with the ActionBar on 3.0-and-later devices.
>
> Anyone have any ideas how I can solve or work around this? (besides
> just not using tabs)

ActionBar.TabListener does not expect android.app.Fragment. It does,
however, supply an android.app.FragmentTransaction as a parameter,
rather than the Android Compatibility Library implementation of
FragmentTransaction.

What seems to be working for me is to simply ignore the passed-in
FragmentTransaction and use your own. See the FeedsTabActivity in this
project:

https://github.com/commonsguy/cw-advandroid/tree/master/Honeycomb/FeedFragments

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android 3.0 Programming Books: http://commonsware.com/books