1

I have a Fragment activity which hosts a fragment list. The fragment activity also has a couple of text views which summarise the data in the fragment list.

  • FragmentActivity = Layout that contains a fragment container, text views and a button.

  • ListFragment = goes inside of the FragmentActivity's fragment container and is a list of data

This works fine as an activity, but now I'm trying to put the whole lot into another fragment container to display it in an action bar tab on another activity. I can only get it to work with the ListFragment (obviously this is because the FragmentActivity can't go inside of a fragment container) but this means that the summary text views and the buttons are missing and I really need them there too.

I wondered if anyone had suggestions of the best way to implement this? Some thoughts of solutions I've had:

  • Change the Layout of the activity holding the tabs if this certain tab is clicked

  • Programmatically add the text views and button to the fragment container if this tab is clicked

  • Add another fragment to the fragment activity, below the list fragment

Either way I'm stumped so any help is really appreciated.

wkdshot
  • 256
  • 1
  • 6
  • 18
  • the simplest (but ugly) solution is to use `LocalActivityManager` and create a `Fragment` that will host your `Activity`. You can find an example how to do it here http://stackoverflow.com/questions/12873213/android-access-mapview-inside-fragment-with-viewpager/12873281#12873281 – Vladimir Mironov Apr 06 '13 at 13:20

1 Answers1

3

Create a Fragment that resembles the layout of you FragmentActivity and add it instead. you can't add the FragmentActivity as a Fragment simply because it's not a Fragment but an Activity that was added a Fragments support for older versions.

So instead of adding you button and TextViews directly to the FragmentActivity Layout. Create a Fragment with the same components and add it to the Activity layout.

That way could could reuse this set of components in another location in your application if you needed to, using the same Fragment.

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • So basically keep the set up how it is but change the fragmentActivity to a fragment? – wkdshot Apr 06 '13 at 13:18
  • Leave the FragmentActivity as it is, but move all it's components to a separate new Fragment and add it instead. – Emil Adz Apr 06 '13 at 13:19
  • I see, logically that seems like a great idea. How do I add the new fragment to the activity? It has three tabs and I only want one of those tabs to contain the textviews/button. – wkdshot Apr 06 '13 at 13:36
  • 1
    You can check this my answer: http://stackoverflow.com/questions/15359993/fragment-remove-issue/15361453#15361453 to get an idea of how to add/remove fragments using the FramgnetManager. – Emil Adz Apr 06 '13 at 13:39