fragment-backstack

How to get the current fragment displayed in a specific tab of a viewpager?

风格不统一 提交于 2019-11-27 15:51:05
问题 I want to get the last fragment in the backstack, or the current displayed it's the same for me, in the tab b_1 . As you can see in the following image, I have a ViewPager, and another one inner tab b . Thus there are four current fragments displayed. Question : How can I get the Fragment 2 instance? I have seen another solutions, but none works for this scenario. Annotation: The fragment to return is not necessary the hosted in the ViewPager. I can have opened two more fragments in a tab.

What does FragmentManager and FragmentTransaction exactly do?

时光总嘲笑我的痴心妄想 提交于 2019-11-27 05:10:19
问题 I have simple code below FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, mFeedFragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); What do these lines of code do? 回答1: getFragmentManager() Return the FragmentManager for interacting with fragments associated with this activity. FragmentManager which is used to create

PopBackStack but keep the first fragment in android

青春壹個敷衍的年華 提交于 2019-11-27 03:55:45
问题 I am working on fragment transaction, and the backstack is like this: fragA => fragB => fragC => fragD I would like to return to fragA after back fromn the fragD fragD => onBackPress => fragA So, I tried code like: getChildFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); but it clear all the backstack , how can I keep the first fragment in the backstack? Thanks a lot 回答1: E.g. you can do following: add fragA without adding it to backStack. So it always be in

Is this the right way to clean-up Fragment back stack when leaving a deeply nested stack?

风格不统一 提交于 2019-11-26 13:59:14
I'm using the Android Compatibility library to implement fragments and have extended the layout sample so that a fragment contains a button which fires off another fragment. In the selection pane on the left I have 5 selectable items - A B C D E . Each loads up a fragment (via FragmentTransaction:replace ) in the details pane - a b c d e Now I've extended fragment e to contain a button which loads up another fragment e1 also in the details pane. I've done this on fragment e 's onClick method as follows: FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft