Search code examples
androidkotlinandroid-arrayadapter

How can I remove an object in Kotlin from ArrayAdapter


I have a LoadingListView which contains this:

 var adapter: ArrayAdapter<*>? = null
    private set

When I delete a item, I do this:

adapter?.remove(wallboardToDelete)

This says: required Nothing! found MyObject

How can I fix this? I tried using in my ListView ArrayAdapter<Any>? and the removeWorks, but then my init from all my classes that extend gives me an issue saying that: I need ArrayAdapter instead of MyArrayAdapterFromListExtendingThis.


Solution

  • Try to change your declaration from ArrayAdapter<*> to ArrayAdapter<Any>.
    <*> is used for represent a fixed type wich you don't know what is, so it can contain Int type, but only Int then