1
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.drawerlayout.widget.DrawerLayout
import com.example.tender.R
import com.example.tender.databinding.FragmentAvailableTenderBinding
import com.example.tender.databinding.FragmentLoginBinding
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.NavigationUI

/**
 * A simple [Fragment] subclass.
 */
class AvailableTenderFragment : Fragment() {

    private lateinit var drawerLayout: DrawerLayout

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        val binding = FragmentAvailableTenderBinding.inflate(inflater)

        drawerLayout = binding.drawerLayout

        **val navController = this.findNavController(R.id.nav_host_fragment)**

        **NavigationUI.setupActionBarWithNavController(this, navController, drawerLayout)**

        NavigationUI.setupWithNavController(binding.navView, navController)

        binding.root

    }
}

"To many arguments for public fun Fragment.findNavController():NAvcontroller defined in androidx.navigation.fragment" is showing when i hover on findnavcontroller.I am unable to resolve the error on the above bold lines.In this case what should I do?

  • `findNavController(R.id.nav_host_fragment)` and `setupActionBarWithNavController` are methods you'd call in your Activity, not in a Fragment. Can you explain the setup of your app? – ianhanniballake Jan 14 '20 at 06:27
  • Thank You for answering! Ohh! yes I wrote It on wrong place, it is helpful for me . – anish sethiya Jan 14 '20 at 06:34

1 Answers1

0

As per the Navigate to a destination documentation, the androidx.navigation.fragment.findNavController you've imported takes no parameters (it finds the parent NavHostFragment of the current Fragment and doesn't need the ID of the NavHostFragment).

The lines you've written, namely findNavController(R.id.nav_host_fragment) and setupActionBarWithNavController() are methods you'd call in an Activity, not in a Fragment.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • If this helped answer your question, make sure to accept the answer to remove this question from the queue of unanswered questions. Best of luck going forward! – ianhanniballake Jan 14 '20 at 14:35
  • This is quite confusing, why : `val navController = findNavController()` `bottomNavigation.setupWithNavController(navController)` Does not work inside the `onActivityCreated()` of a fragment that has a navHost? – dnhyde Apr 03 '20 at 19:21