the spinner doesnt work in my kotlin fragment

Refresh

6 days ago

Views

14 time

1

I want a spinner to show up to make the user choose between two types and it doesn't work

  inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
       spinner2?.adapter = ArrayAdapter(activity, R.layout.support_simple_spinner_dropdown_item, types) as SpinnerAdapter
        spinner2?.onItemSelectedListener = object :AdapterView.OnItemSelectedListener{
            override fun onNothingSelected(parent: AdapterView<*>?) {
                println("erreur")
            }

            override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
                val type = parent?.getItemAtPosition(position).toString()
                println(type)
            }

        }
        return inflater.inflate(R.layout.fragment_add, container, false)
    }

0 answers