Kotlin Jetpack导航片段中的微调器

时间:2019-11-29 09:11:45

标签: android kotlin android-jetpack android-jetpack-navigation

我无法使微调器在片段中正常工作。我收到的错误是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
}

1 个答案:

答案 0 :(得分:1)

尝试将this替换为requireContext()

 val adapter : ArrayAdapter<String> = ArrayAdapter(requireContext(), R.layout.support_simple_spinner_dropdown_item, list)