Yunus Berk KAYNAK
Yunus Berk KAYNAK

Reputation: 23

findNavController is missing and not working

i was doing this https://youtu.be/GOpeBbfyb6s?t=1405 with navigation arch but i cant type it.findNavController it is showing red

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    lgnbtn.setOnClickListener {
        val nameBundle = Bundle()
        nameBundle.putString("name",idfield.text.toString())
        it.findNavController().navigate(R.id.mainFragment, nameBundle)
    }
}

Upvotes: 0

Views: 5374

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199805

As per the Declaring Navigation dependencies, you must use the -ktx versions of the dependencies to use Kotlin extensions, such as the findNavController() extension for View.

Therefore, replace any dependencies on navigation-fragment with navigation-fragment-ktx and similarly for navigation-ui with navigation-ui-ktx.

Upvotes: 5

Related Questions