我试图将 Parcelable 参数传递给嵌套图,但生成的函数需要 0 个参数。
我发现了这个线程,我看不出我拥有的和他们拥有的之间的区别。
这是我的 XML,我删除了代码以仅显示问题
logged_content_nav_graph.xml
<?xml version="1.0" encoding="utf-8"?>
<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/logged_content_nav_graph"
app:startDestination="@id/chooseCategoryFragment">
<fragment
android:id="@+id/productDetailFragment"
android:name="com.vendyapp.vendy.features.loggedcontent.productdetail.ui.ProductDetailFragment"
android:label="fragment_product_detail"
tools:layout="@layout/fragment_product_detail" >
<action
android:id="@+id/action_productDetailFragment_to_loginAndRegisterFragment"
app:destination="@id/login_nav_graph" />
<argument
android:name="product"
app:argType="com.vendyapp.vendy.features.loggedcontent.home.Product" />
</fragment>
<include app:graph="@navigation/login_nav_graph"/>
login_nav_graph.xml(嵌套)
<?xml version="1.0" encoding="utf-8"?>
<navigation android:id="@+id/login_nav_graph"
app:startDestination="@id/loginAndRegisterFragment"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<fragment
android:id="@+id/loginAndRegisterFragment"
android:name="com.vendyapp.vendy.features.login.ui.LoginAndRegisterFragment"
android:label="fragment_login_and_register"
tools:layout="@layout/fragment_login_and_register">
<argument
android:name="product"
app:argType="com.vendyapp.vendy.features.loggedcontent.home.Product"
app:nullable="true" />
<action
android:id="@+id/action_loginAndRegisterFragment_to_registerFragment"
app:destination="@id/registerFragment" />
<action
android:id="@+id/action_loginAndRegisterFragment_to_loginFragment"
app:destination="@id/loginFragment" />
</fragment>
</navigation>
在我的 Kotlin 课程中,我会使用这样的导航图
val action = ProductDetailFragmentDirections.actionProductDetailFragmentToLoginAndRegisterFragment(product)
findNavController().navigate(action)
但是它说这个函数需要 0 个参数。
我错了什么?预先感谢。
我也遇到了这个问题,我在没有考虑错误的情况下运行了该项目,并且它工作正常。