【问题标题】:How should I handle Navigation within ViewPager Fragment with Navigation Architecture Components, and Single Activity Approach我应该如何使用导航架构组件和单活动方法处理 ViewPager 片段中的导航
【发布时间】:2019-03-30 03:39:34
【问题描述】:

这是我的单一活动方法:

MainActivity 有 NavHost

MainFragment 带有 AppBarLayout、TabLayout、ViewPager 等

MainFragment 在 ViewPager 中有 2 个(或更多)片段 -> {

CustomerListFragment -> 将导航到 CustomerDetailFragment

EmployeesListFragment -> 将导航到 EmployeeDetailFragment

}

CustomerDetailFragment(具有完全不同的设计布局)

EmployeeDetailFragment(它也有完全不同的设计布局)

* 我的问题是,我将如何使用导航架构组件(androidx)处理这些列表片段到详细片段之间的导航*

【问题讨论】:

    标签: android android-fragments android-viewpager androidx navigation-architecture


    【解决方案1】:

    假设你在 Fragment A 中,ViewPager 是 Fragment B 然后你尝试从 B 导航到 C

    由于在 ViewWpager 中,片段不是目的地,因此您的图表不会知道您在 B 上。

    解决方案可以是使用 B 中的 ADirections 导航到 C

    【讨论】:

    • 如果你这样做,你不会失去viewpager标签布局吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    • 2020-10-20
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 1970-01-01
    相关资源
    最近更新 更多