Fragment具有空参数safeargs

问题描述 投票:0回答:1

如何使用导航架构组件safeargs将参数传递给对话框片段?下面是我当前的实现

开始片段

val navController = findNavController()
val action =
            QuestionListFragmentDirections.actionQuestionListFragmentToCustomDialogFragment(args.templateFlag)
        navController.navigate(
            action
        )

目标片段

   args.templateFlage //supposed to return a boolean value 
   //but throws java.lang.IllegalStateException: Fragment QuestionTypeDialogFragment{e8be5e1} 
   (47b305ea-35b2-49e0-b378-d31a08ba9a41) QuestionTypeDialogFragment} has null arguments
android-navigation android-architecture-navigation
1个回答
0
投票

例如,您必须在xml导航声明中添加默认值:

           <argument
            android:name="ArgName"
            android:defaultValue="@null"
            app:argType="boolean"
            app:nullable="true" />
© www.soinside.com 2019 - 2024. All rights reserved.