Any idea why my adapter won't recognize the functi...
# android
c
Any idea why my adapter won't recognize the function here? Excuse the messy code. This is just driving me nuts.
a
You're trying to call a method as a static function. What you want is
Copy code
interface OnDeleteItemClickListener {
    companion object {
        fun onDeleteItemClick(position: BarrelFreestyle)
    }
}
https://www.programiz.com/kotlin-programming/companion-objects
If you want to set that function as the listener though, you'll probably want to do
Copy code
holder.deleteIcon.setOnClickListener(OnDeleteItemClickListener::onDeleteItemClick)
if it is supposed to be a method, that is
c
Thanks so much. I'll take a look at that. I still can't get it to work but I'm getting really tangled up and need to take a break. I’m mostly not understanding why it works to get the function from the other adapter’s interface and not from this one. But getting too frustrated to think clearly 😑
a
I've been there before :)
g
Looking at the logic, I'm assuming you need to pass an instance of
OnDeleteItemClickListener
to the adapter instead of calling the companion object.