Search code examples
javaandroidkotlinbaseadapter

MutableList clear() and addAll() behaves strangely


Basically I'm using a method inside of a BaseAdapter to refresh it. It actually worked for plenty functions, however once I tried to implement a new one and used this its custom method to refresh it, it just cleared control MutableList. The control MutableList and the MutableList I'm passing throught the method is the same, however I highly doubt Kotlin would keep reference that deep. So I ended up placing logs everywhere and foud out, that the .clear() call cleared even the MutableList I'm passing. Tried even re initializating the MutableList itself before I'm passing it, so there is no chance of any sort of reference. So I guess I'm asking if .clear() method is normally used or is it something that actually doesn't as it should be.

enter image description here

enter image description here


Solution

  • Don't make it hard just use this code and let it go

    fun updateData(list :MutableList<MarketOffer>){
        this.itemsListAdapter = list
        this.notifyDataSetChanged()
    }