Android – implementation code for switching fragment page function
Scenario: use fragment to realize page cutting.
Class structure:
1: Activity
Getsupportfragmentmanager(). Begintransaction() is used in the activity to fill in a fragment (fragmenta for management)
Activity part code:
XML:
2: Fragmenta
Load a main fragmenta to manage other sub blade fragmentx.
Now, for example, there are two sub blades fragmentb and fragmentc
Fragmenta uses fragmentmanager and fragmenttransaction to manage the switching between fragmentb and fragmentc
Fragmenta Code:
XML:
3: Fragmentx (fragmentb, fragmentc)
The logic of the sub page is defined according to the specific business, and the implementation is the same as that of the general fragmeng
For example:
Here, you can simply implement the function of page cutting by switching fragment with the bottom tab
Attached drawings:
PS: error during implementation
Correct method: false should be added to the initialization layout of the relevant fragment to establish a relationship with the parent class layout.
Reason: if it is not added, the view system from the inflator will bind an unknown parent class. At this time, when you bind this fragment to an activity or another fragment as a child page, the above error will occur.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.