【发布时间】:2020-07-06 08:20:56
【问题描述】:
这是我的导航文件
<navigation
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigation"
app:startDestination="@id/fragmentA">
<fragment
android:id="@+id/fragmentA"
android:name="com.example.fragmentdatapassings.FragmentA"
android:label="Fragment A">
<action
android:id="@+id/action_fragmentA_to_fragnentB"
app:destination="@+id/fragmentB" />
<argument
android:name="x"
app:argType="integer" />
</fragment>
<fragment
android:id="@+id/fragmentB"
android:name="com.example.fragmentdatapassings.FragmentB"
android:label="FragmentB">
</fragment>
</navigation>
这是片段方向数据传递的代码。
val x : Int = 10
val action = FragmentADirections.actionFragmentAToFragnentB(x)
Navigation.findNavController(requireView()).navigate(action)
上面第二行显示错误
公开娱乐的争论太多
当我将鼠标悬停在错误上时,它显示添加参数 x,我确实单击它并且它确实 在 FragmentADirections 中添加参数 x。但是再次构建应用程序后,它显示错误 再次。
【问题讨论】:
-
您可以使用安全的 Args 在导航组件中的片段之间传递值。检查此代码实验室:codelabs.developers.google.com/codelabs/…
-
我所做的都是一样的。
标签: android kotlin navigation fragment