我应该如何将null这样的String参数作为默认值传递:
<argument
android:name="profile_id"
android:defaultValue="???"
app:argType="string"
app:nullable="true" />
Run Code Online (Sandbox Code Playgroud)
如果参数为空,应该有一种传递方法null吗?
我在 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 Project和Rebuild 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