Home > Mobile >  Use Navigation components, how to implement multiple fragments between arbitrary jump
Use Navigation components, how to implement multiple fragments between arbitrary jump

Time:09-30

My function menu is used an Activity, jump through the Navigation control, each function interface is a Fragment

Usually jump from fragments of menu interface (Fm) to jump to the corresponding function interface fragments (Fn), such as Fm and F1, Fm - F2, Fm, F3 etc.

But there is a demand that when information push, after click on the message, need according to the message content to jump to the corresponding interface, if at this point in the menu interface Fm, so to say, I can take the Action Id as a parameter, realize the jump, but if the interface in F1, messages need to jump to the F3 interface, system don't have the jump of the Action, this kind of circumstance how to realize the jump?

PS: it is impossible for me to do all the function of the interface between fragments wires, too many function interface

I am a beginner Android development, the design may have many shortcomings, hope everybody a great god teach

CodePudding user response:

Can use the viewpager nested multiple fragments by viewpager. SetCurrentItem (int) to control to display the fragments

CodePudding user response:

I think this kind of scenario, you should consider using the activity, or your fragments in a separate parcel only fragments for filling in the activity

CodePudding user response:

 
NavController NavController=Navigation. FindNavController (v);
NavController. Navigate (R.i d.f ragment_target));

CodePudding user response:

I demand is the same, each fragment is connected to the target fragments, which fragments, and then when the activity to judge the current really tedious, I was wondering if I like this: usually inherited a basefragment fragments and jump in basefragment when determining if a current homefragment, not is invoked automatically return to the Navigation. FindNavController (it). The popBackStack (), when for homefragment jump,

CodePudding user response:

Then the implementation is like this:
Activity:
Private fun gotoGongDan () {
SpUtil. WriteBoolean (this, KEY_GOTO_TARGET, true)
When (val fragments=getCurrentFragment ()) {
Is BaseFragment - & gt; Fragments. GotoTargetFragment ()
}
}

Basefragment:
Override fun onViewCreated (view: the view, savedInstanceState: Bundle? {
GotoTargetFragment ()
}

Fun gotoTargetFragment () {
If (SpUtil. ReadBoolean (MyApp. Instance, KEY_GOTO_TARGET, false)) {
The view? . Let {
If (layoutId!=R.l ayout. Fragment_home) {
Navigation. FindNavController (it). PopBackStack ()
} else {
Navigation. FindNavController (it). Navigate (da ction_homeFragment_to_targetFragment R.i)
SpUtil. WriteBoolean (MyApp. Instance, KEY_GOTO_TARGET, false)
}
}
}
}

CodePudding user response:

I think we can judge the current page is the home, not just popBackStack (home, false), and then through the home - & gt; Target fragments of the action to jump,

CodePudding user response:

Navigation is also a lot of pit, I made at the bottom of the Navigation + BottomNavigationView Navigation, in the current by the bottom of the page click on the previous page, will jump to perform lifecycle,
Point into the possible source, incredibly in BottomNavigationView setOnNavigationItemSelectedListener do jump directly according to the id of menuItem, navController. Navigate (item, getItemId (), null, options); Just add a judgment,

Navigation saw last time there was a singinTop effect, topic main know
  • Related