【问题标题】:spinner crashing using onItemSelectedListener微调器使用 onItemSelectedListener 崩溃
【发布时间】:2020-06-06 16:35:13
【问题描述】:

美好的一天 我有一个定制的微调器,它显示字符串数组没有任何问题。但是当我添加 onItemSelectedListener 时,我的应用程序会在加载片段时崩溃。

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
  auth = Firebase.auth
  // show back button
  val activity = activity as? MainActivity
  activity?.supportActionBar?.setDisplayHomeAsUpEnabled(true)

  val result = inflater.inflate(R.layout.fragment_new_key, container, false)

  val spinner: Spinner = result.findViewById(R.id.spinner_Category)
  ArrayAdapter.createFromResource(
     requireContext(), R.array.keyCategory, R.layout.spinner_item
                                 ).also { adapter ->
     spinner.adapter = adapter
  }
  // without adding the below, the application will work smoothly
  spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
     override fun onNothingSelected(parent: AdapterView<*>?) {
        TODO("Not yet implemented")
     }

     override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
        TODO("Not yet implemented")
     }

  }
  return result

}

能否请您帮忙,是否与导致应用程序崩溃的微调器有冲突?

谢谢。

【问题讨论】:

  • 你收到什么崩溃信息?

标签: android kotlin spinner


【解决方案1】:

删除这些行

TODO("Not yet implemented")

TODO 抛出NotImplementedError

【讨论】:

  • 很好,由于某种原因,我通过它被评论:P
  • 哈哈,搞定我们,快乐编码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多