In android, how do I create different fragments / actions in each tab that are stored in tabs?

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

I want my user interface to be laid out as shown above. I 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 so that each tab has a fragment and selecting something on the fragment to display another fragment.

Now the problem: I do not see how I can support different fragments of fragments in each tab. I want to be able to switch from fragment to FragmentC when using the back button in Tab2. Switching to Tab1 should show me FragmentB and let me go to FragmentA using the BACK button. Is there a way to have multiple fragment stacks as described above?

+4
source share
5 answers

The template should look like this:

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

You cannot do (as far as I know) what you are trying to do with the current APIs. Check here for more details.

+1
source

Inside your SDK, you have APIdemos samples ... there you will find sample code ... to import it into the project. create a new one from an existing source and go to / androisdkdirectory / samples / android -x / Apidemos and then finish

you will find a Java file and a view of the various types of tabs there, it will be very useful to learn new types that you can use

0
source

I guess this is possible if you just avoid using backstack and link to your snippets by tags. For example, if you give fragment C a tag "fragmentC", then if fragment D is visible, you can create a FragmentTransaction that replaces fragment D with a fragment. The back stack seems more valuable when your transitions are defined as you are here.

0
source

Why don't you call:

 fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); 

Each time you click a tab

0
source

Source: https://habr.com/ru/post/1396751/


All Articles