I have an interface in my Adapter
class:
interface OnItemClickListener {
fun onItemClick(view: View)
}
TAKE NOTE that my interface
is in Kotlin.
which I want to set via this method:
public fun setItemClickListener(itemClickListener: OnItemClickListener) {
this.onItemClickListener = itemClickListener
}
How do I use the setItemClickListener
method in my Fragment
class like what I used to do in Java? i.e.
adapter.setItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(View view) {
// do something
}
}
I know that I can use an onItemTouchListener
but I am still new to Kotlin and I'm trying to learn some techniques like Lambdas
and such.
Without lambda you can do it like this
adapter.setItemClickListener(object :View.OnItemClickListener{
override fun onItemClick(p0: View?) {
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With