在一個活動中,兩個片段在切換時傳遞一些字串。
大堂碎片
button.setOnClickListener {
LobbyFragmentDirections.actionLobbyFToGameF(myTitle)
findNavController(requireActivity(), R.id.fragment_container_view).navigate(R.id.gameFragment)
}
游戲片段
private val args: GameFragmentArgs by navArgs()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_game, container, false)
UseArgument(args.argumentTitle)
}
導航圖:游戲片段屬性

問題
當獲取 Game Fragment 中的引數時onViewCreated,它會拋出一個java.lang.IllegalArgumentException: Required argument "argumentTitle" is missing
uj5u.com熱心網友回復:
button.setOnClickListener {
val dir = LobbyFragmentDirections.actionLobbyFToGameF(myTitle)
findNavController().navigate(dir)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/342713.html
標籤:安卓 科特林 android-fragments 争论 android-safe-args
上一篇:輸入值未在我在Intents中傳遞的另一個活動中更新
下一篇:切換片段時導航重置
