我知道可以使用源片段中的Action传递单个参数
override fun onClick(v: View) {
val amountTv: EditText = view!!.findViewById(R.id.editTextAmount)
val amount = amountTv.text.toString().toInt()
val action = SpecifyAmountFragmentDirections.confirmationAction(amount)
v.findNavController().navigate(action)
}
并按照android docs中的指定在目标片段中获取它
val args: ConfirmationFragmentArgs by navArgs()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val tv: TextView = view.findViewById(R.id.textViewAmount)
val amount = args.amount
tv.text = amount.toString()
}
请让我知道有什么方法可以通过TypeSafe方式传递多个参数
是,您可以通过在导航图中为片段定义多个参数,然后将它们传递给代码中的action
来实现。这是一个例子: