When I attempt to display two input views from one fragment to another, I get a problem. The navigation is fully functional. But the values appear as resources.
binding.buttonLogin.setOnClickListener{
val userName = binding.etUserName.toString()
val password = binding.etPassword.toString()
val action = LoginFragmentDirections.actionLoginFragmentToWelcomeFragment(userName, password)
findNavController().navigate(action)
}
On WelcomeFragment I receive the values in the following way:
val args: WelcomeFragmentArgs by navArgs()
binding.tvUserName.text = args.userName
binding.tvPassword.text = args.password
You are taking the view itself instead of its value. To do so, grab the value, not the view.
Alternatively, you can pass data between destinations with Bundle objects.
Create a Bundle object and pass it to the destination using navigate(), as shown below:
In your receiving destination’s code, use the getArguments() method to retrieve the Bundle and use its contents: