Trying to use a spinner, to make it dynamic I am using an Arrayadapter. However I am not able to remove items, it just keeps crashing. See code below.
The attribute.
private lateinit var adp : ArrayAdapter<CharSequence>
And the initialization of the adapter.
adp = ArrayAdapter.createFromResource(this,
R.array.values_array,
android.R.layout.simple_spinner_item)
adp.also { adapter ->
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner.adapter = adapter}
After one of the items has been clicked I would like to remove it from the spinner when another button is clicked, using code below.
button.setOnClickListener{
adp.remove(spinner.selectedItem.toString())
adp.notifyDataSetChanged()
}
On the row of the remove, the exception java.lang.UnsupportedOperationException is thrown.
Since this is the first time using Kotlin I find it hard to pin down the source of the issue.
question from:
https://stackoverflow.com/questions/66065393/remove-item-from-arrayadapter-not-working 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…