如何解决使用Android导航safeArgs
我正在android中创建导航图,并为目的地指定了args,但是当我调用该函数时,它说了太多参数。
-
已在build.gradle(应用程序)
上进行设置apply plugin: 'androidx.navigation.safeargs'
-
已在build.gradle(。)
上进行设置dependecies { classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha05" }
-
这是我导航的来源
<fragment
android:id="@+id/game_fragment_destination"
android:name="com.example.apparchitectureuilayer.screen.game.GameFragment"
android:label="GameFragment"
tools:layout="@layout/fragment_game">
<action
android:id="@+id/action_game_fragment_destination_to_scoreFragment"
app:destination="@id/score_fragment"
app:launchSingleTop="true"
app:popUpTo="@+id/title_destination" />
</fragment>
- 这是我导航的目的地
<fragment
android:id="@+id/score_fragment"
android:name="com.example.apparchitectureuilayer.screen.score.ScoreFragment"
android:label="ScoreFragment"
tools:layout="@layout/fragment_score">
<action
android:id="@+id/action_score_fragment_to_game_fragment_destination"
app:destination="@id/game_fragment_destination" />
<argument
android:name="score"
android:defaultValue="0"
app:argType="integer" />
</fragment>
- 这是我的导航来源的kotlin代码
class GameFragment : Fragment() {
private var word = ""
private var score = 0
private lateinit var wordList: MutableList<String>
private lateinit var binding: FragmentGameBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(
inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_game,container,false)
}
private fun gameFinished() {
val action = GameFragmentDirections.actionGameFragmentDestinationToScoreFragment(score)
NavHostFragment.findNavController(this).navigate(action)
}
}
当我在未使用的gameFinished函数中调用它时,GameFragmentDirections.actionGameFragmentDestinationToScoreFragment(score)
有人在说很多论点,知道如何解决吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。