0

I cannot get the spinner to work normally in my fragment. The error I'm getting is "ArrayAdapter function cannot be called" on the ArrayAdapter line.

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    navController = Navigation.findNavController(view)
    val list : MutableList<String> = ArrayList()
    for (i in 1..1000)
        list.add("Item $i")
    val adapter :ArrayAdapter<String> = ArrayAdapter(this, R.layout.support_simple_spinner_dropdown_item, list)
    spinnerCompany.adapter = adapter
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

1

Try replacing this with requireContext()

 val adapter : ArrayAdapter<String> = ArrayAdapter(requireContext(), R.layout.support_simple_spinner_dropdown_item, list)
Dmitrii Leonov
  • 1,331
  • 1
  • 15
  • 25