【发布时间】:2019-11-23 12:38:41
【问题描述】:
我在 Android Studio 中使用 Navigation Editor 来实现 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>
在我的片段中,我将参数发送为
view.findNavController().navigate(GameFragmentDirections.actionGameFragmentToGameWonFragment(numQuestions, questionIndex))
但是,GameFragmentDirections.actionGameFragmentToGameWonFragment() 不想接受参数。我试过Clean Project和Rebuild Project。
这是投掷:
Too many arguments for @NonNull public open fun actionGameFragmentToGameWonFragment(): GameFragmentDirections.ActionGameFragmentToGameWonFragment defined in com.example.android.navigation.GameFragmentDirections
【问题讨论】:
-
我也遇到了同样的问题。但我需要为我的片段设置一个默认值。有没有默认值的解决方案?
-
嗨吉姆,有什么解决方案吗?
标签: android android-studio androidx android-jetpack android-jetpack-navigation