android – I have a spinner I want to take the spinner element save it as a string and pass it to another activity in kotlin-ThrowExceptions

Exception or error:

I have a spinner

 val spinner = findViewById<Spinner>(
                val vehicle = arrayOf(
                val adapter = ArrayAdapter<String>(this, R.layout.custom_spinner, vehicle)

                spinner.adapter = adapter

                spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
                  override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id:Long) {

                  if (position == 0) {
                      ttx_constraint_0.visibility = View.VISIBLE
                      image_check.setOnClickListener {
                          mViewModel.mkVehicleCompletedEvent.observe(this@AddVehicleActivity, Observer {

                     override fun onNothingSelected(parent: AdapterView<*>) {

On button click I call the function

 private fun mkVehicleAutocranes() {

I think i save value element of spinner and pass it to another activity. But it’s not work.
Please! Somebody help me!

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *