IllegalStateException: Link does not have a NavController set

前端 未结 9 2236
故里飘歌
故里飘歌 2020-11-29 03:58

I\'m using Android Navigation Component for Navigation. I have a LoginFragment which has a button to transition to SignUpFragment. On clicking the button I\'m getting this e

9条回答
  •  迷失自我
    2020-11-29 04:23

    Use the view of fragment such as onViewCreated

     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
    
        val navController = Navigation.findNavController(view)
    
        binding.signUpLink.setOnClickListener {
                navController.navigate(R.id.action_loginFragment_to_signUpFragment)
        }
    

提交回复
热议问题