相关疑难解决方法(0)

如何使用SafeArgs将“ null”设置为可为空的参数的默认值?

我应该如何将null这样的String参数作为默认值传递:

<argument
    android:name="profile_id"
    android:defaultValue="???"
    app:argType="string"
    app:nullable="true" />
Run Code Online (Sandbox Code Playgroud)

如果参数为空,应该有一种传递方法null吗?

android android-architecture-navigation androidx

10
推荐指数
1
解决办法
1035
查看次数

androidx 导航:@NonNull 公共开放乐趣的参数太多

我在 Android Studio 中使用导航编辑器来实现Safe Args.

我在一个片段中接受参数为

 <fragment
    android:id="@+id/gameWonFragment"
    android:name="com.example.android.navigation.GameWonFragment"
    android:label="@string/android_trivia"
    tools:layout="@layout/fragment_game_won">

    <action
        android:id="@+id/action_gameWonFragment_to_gameFragment"
        app:destination="@id/gameFragment"
        app:popUpTo="@+id/titleFragment">
    </action>
    <argument
        android:name="numQuestions"
        app:argType="integer"
        android:defaultValue="0" />
    <argument
        android:name="numCorrect"
        app:argType="integer"
        android:defaultValue="0" />
 </fragment>
Run Code Online (Sandbox Code Playgroud)

在我的片段中,我将参数发送为

view.findNavController().navigate(GameFragmentDirections.actionGameFragmentToGameWonFragment(numQuestions, questionIndex))
Run Code Online (Sandbox Code Playgroud)

但是,GameFragmentDirections.actionGameFragmentToGameWonFragment()不想接受论据。我试过Clean ProjectRebuild Project

这是抛出:

Too many arguments for @NonNull public open fun actionGameFragmentToGameWonFragment(): GameFragmentDirections.ActionGameFragmentToGameWonFragment defined in com.example.android.navigation.GameFragmentDirections
Run Code Online (Sandbox Code Playgroud)

android android-studio android-jetpack androidx android-jetpack-navigation

7
推荐指数
3
解决办法
5079
查看次数