Home > Back-end >  Error while calling Navigation Components while using ViewPager 2
Error while calling Navigation Components while using ViewPager 2

Time:11-03

I have a hard time with trying to learn Navigation Components. In my app, I have 6 fragments.

  • Four of them are swipeable by using ViewPager 2
  • Fifth fragment is not implemented in ViewPager, so user can't go there by swipping
  • Sixth fragment is just a host for ViewPager, since the other fragments are used by Navigation Components

I can swipe fragments for now, but whenever I try to use Navigation Components, I getting error about action/destionation. It's simply about calling for example ActionFrag1ToFrag5 from my Host Fragment

It seems like I can browse through fragments, but I can't cast any Navigation Component functions, because the fragment stays the same, it doesn't change label after swipe to another one.

Is there a way to get proper NavController from specific fragment, or it's just my poor implementation?

CodePudding user response:

If Frag1, Frag2, Frag3, and Frag4 are those in the ViewPager and you want to go to Frag5.

The direction needs to be from the Frag6 that is hosting the ViewPager to the Frag5.

  • Related