gpt4 book ai didi

android - 当我将相同的 fragment 添加到第二个导航图中时,无法识别操作类

转载 作者:行者123 更新时间:2023-12-05 03:50:16 25 4
gpt4 key购买 nike

我需要将相同的 fragment 添加到不同的导航图中。这是第一张图的一段代码(mobile_navigation)

<fragment
android:id="@+id/nav_contactanos"
android:name="com.engie.mexico.micuenta.Fragments.FragmentContactanosCliente"
tools:layout="@layout/fragment_contactanos_cliente" >
<action
android:id="@+id/action_nav_contactanos_to_nav_aviso_privacidad"
app:destination="@id/nav_aviso_privacidad" />
<action
android:id="@+id/action_nav_contactanos_to_nav_terminos_condiciones"
app:destination="@id/nav_terminos_condiciones" />
<action
android:id="@+id/action_nav_contactanos_to_nav_mensaje_usuario"
app:destination="@id/nav_mensaje_usuario" />
</fragment>

第二个导航图中的第二个代码 fragment (navigation_inicial)

    <fragment
android:id="@+id/nav_contactanos_cliente"
android:name="com.engie.mexico.micuenta.Fragments.FragmentContactanosCliente"
tools:layout="@layout/fragment_contactanos_cliente" >
<action
android:id="@+id/action_nav_contactanos_cliente_to_nav_mensaje_usuario"
app:destination="@id/nav_mensaje_usuario" />
<action
android:id="@+id/action_nav_contactanos_cliente_to_nav_terminos_condiciones"
app:destination="@id/nav_terminos_condiciones" />
<action
android:id="@+id/action_nav_contactanos_cliente_to_nav_aviso_privacidad"
app:destination="@id/nav_aviso_privacidad" />
</fragment>

当我尝试 MakeProject 时,构建输出显示错误:

C:\Android\MiCuenta\app\src\main\java\com\engie\mexico\micuenta\Fragments\FragmentContactanosCliente.java:478: error: cannot find symbol
FragmentContactanosClienteDirections.ActionNavContactanosToNavMensajeUsuario action = symbol: class ActionNavContactanosToNavMensajeUsuario

位置:类 FragmentContactanosClienteDirections

但是当我注释第二段代码(navigation_inicial)时,问题就消失了。问题是我需要第二段代码,因为我需要记忆 fragment 并与它共享 bundle ,与其他信息一起显示不同的东西......如何实现?

我也分享图的设计:

移动导航

mobile_navigation.xml (design)

navigation_inicial

navigation_inicial.xml (design)

最佳答案

Directions 类的名称基于 Fragment 的名称,一次只能有一个特定类的实例。根据 this issue with Safe Args ,当您从另一个图中覆盖一个方向类时没有警告 - 最后一个获胜。这就是为什么在不同的图中重复使用相同的 fragment 会使第一个图中的 Directions 类无效。

当然,如果你的第二个图的 fragment 有不同的 Action 、不同的参数,或者任何不同的东西,它也应该有一个不同的 fragment 类——如果你的单个 fragment 类要使用另一个图的参数或 Action ,它们会失败,因为它们不存在于该图中。

如该错误中所述:

For a destination with an android:name, you'd want to include that android:name in only one place in your graph, referencing that shared destination from all of the places that need access to it (as a destination can access any sibling destinations of their parent graph).

关于android - 当我将相同的 fragment 添加到第二个导航图中时,无法识别操作类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63495305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com