我无法使微调器在片段中正常工作。我收到的错误是ArrayAdapter行上的“无法调用ArrayAdapter函数”。
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
}
答案 0 :(得分:1)
尝试将this
替换为requireContext()
val adapter : ArrayAdapter<String> = ArrayAdapter(requireContext(), R.layout.support_simple_spinner_dropdown_item, list)