I just started to learn Kotlin yesterday, so brace yourself for a potentially stupid question.
class MyCustomViewAdapter(private val callback: (position: Int) -> Unit) : RecyclerView.Adapter<MyCustomViewHolder>() {
...
}
When I try to initialize this class, I need to pass in a callback parameter to receive events.
MyCustomViewAdapter({ position -> onClickFlowerCallback(position)}) // this works
MyCustomViewAdapter(onClickFlowerCallback) // this doesn't work?
private fun onClickFlowerCallback(position: Int) {
println("We have successfully received click from position #" + position.toString())
}
Can someone enlighten me to why this is happening?