4
 TAB1          TAB2      TAB3
   |            |          |
 FragmentA     FragmentC  FragmentE
   |             |         |
FragmentB     FragmentD  FragmentF

I want my user interface to be layed out as shown above. I have read about how fragments work and it looks like I should be able to implement a user interface that allows me to switch between tabs such that each tab has a fragment and selecting something on a fragment will cause another fragment to be displayed.

Now the problem: I do not see how I can maintain different fragment stacks within each tab. What I want is to be able to go from fragmentD to FragmentC when using the back button within Tab2. Switching to Tab1 should show me FragmentB and allow me to navigate to FragmentA using the BACK button. Is there a way to have multiple fragment stacks like how I have described?

5 Answers5

1

The pattern should be like this :

   TAB1          TAB2         TAB3
    |             |            |
 Activity 1    Activity 2  Activity 3
    |             |            |
 FragmentA     FragmentC   FragmentE
    |             |            |
 FragmentB     FragmentD   FragmentF

You cannot do(as far as my knowledge goes) what you are trying to do with the current APIs. Look here for more details.

Community
  • 1
  • 1
500865
  • 6,920
  • 7
  • 44
  • 87
1

Use android ViewPager with fragment check this

http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentPagerSupport.html

Munish Kapoor
  • 3,141
  • 2
  • 26
  • 41
0

Inside Your SDK you have de APIdemos samples... there you will find the example code..., to import it go to project. create new, from existing source and go to /androisdkdirectory/samples/android-x/Apidemos and then finish

you will find a Java file and the view of the different tab types there, will be very useful l to learn new views that you can use

Pedro Teran
  • 1,200
  • 3
  • 17
  • 43
0

My guess is that this is possible if you just avoid using the backstack and reference your fragments by tags. For instance, if you give fragmentC the tag "fragmentC" then if fragmentD is visible, you can create a FragmentTransaction that replaces fragmentD with fragmentC. The back stack seems to be more valuable when your transitions are as defined as you layout here.

Nick Campion
  • 10,479
  • 3
  • 44
  • 58
  • I ended up with a compromise in my design where clicking on a different Tab will cause the current tab to completely unwind. – Nikhil Sohoni Feb 20 '12 at 23:54
0

Why don't you call:

fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);

Whenever tab is clicked?

ofirbt
  • 1,846
  • 7
  • 26
  • 41