小编MaY*_*Yar的帖子

如果默认值 null,如何使用 android 导航传递值

我正在使用带有安全参数的 Android 导航组件。我将参数设置为可以为空,并且默认值也为空。

问题是当我想传递任何值时会显示错误:

required: no arguments
found: Character
reason: actual and formal argument lists differ in length
Run Code Online (Sandbox Code Playgroud)

我的片段 XML 代码:

<fragment
        android:id="@+id/bookListFragment"
        android:name="com.example.bookstory.UI.Fragments.BookListFragment"
        android:label="fragment_book_list"
        tools:layout="@layout/fragment_book_list">
            <argument
            android:name="character"
            app:argType="com.example.bookstory.DAO.Character"
            app:nullable="true"
            android:defaultValue="@null" />
</fragment>
Run Code Online (Sandbox Code Playgroud)

我的行动:

      <action
            android:id="@+id/action_bookDescriptionFragment_to_bookListFragment"
            app:destination="@id/bookListFragment"
            app:popUpTo="@id/bookListFragment"
            app:popUpToInclusive="true" />
Run Code Online (Sandbox Code Playgroud)

我不明白问题是什么 - 当我删除默认值时就可以了。

navigation android android-safe-args

4
推荐指数
1
解决办法
3300
查看次数

标签 统计

android ×1

android-safe-args ×1

navigation ×1