从Android ViewPager2儿童片段导航到另一个片段
有没有办法从ViewPager2的孩子碎片到另一个碎片? 假设我有一个父片[parent fragment]仅包含viewPager2和ablayout。我有2个孩子的碎片[Childragment1和Childragment2]由FragmentStateDapter创建。我想从Childrenfragment2导航到另一个FragmentB,以便当我从FragmentB导航时,以显示父母段落到Childfragment2的位置?
例如:ChildFragment1-> ChildFragment2-> fragmentb-> childragment2
我得到:
java.lang.IllegalArgumentException: Navigation action/destination id:actionChildFragment2_to_FragmentB cannot be found from the current destination
Is there a way to navigate from a child fragment of ViewPager2 to another fragment?
Let's say I have a parent fragment [ParentFragment] containing only a ViewPager2 and a TabLayout. I have 2 children fragments [ChildrenFragment1 and ChildrenFragment2] created with FragmentStateAdapter. I want to navigate from ChildrenFragment2 to another FragmentB so that when i navigate back from FragmentB, to show position of the ParentFragment to ChildFragment2?
ex: ChildFragment1 -> ChildFragment2 -> FragmentB -> ChildFragment2
I get:
java.lang.IllegalArgumentException: Navigation action/destination id:actionChildFragment2_to_FragmentB cannot be found from the current destination
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个解决方案,将当前页面保留在ViewModel Livedata属性中,将其设置在ParentFragment内部的页面上:
并观察ParentFragment内部的页面更改:
ParentViewModel:
I found a solution, i keep the current page in a ViewModel LiveData property, setting it on page change inside the ParentFragment:
and observe the page change inside the ParentFragment:
The ParentViewModel: