So I got this function in Kotlin:
private fun initComponents(){
lv = findViewById(R.id.listView)
lv?.setOnItemLongClickListener { _, _, i, _ ->
removeItem(i) <- Error Here
}
}
fun removeItem(index : Int){
items.removeAt(index)
}
where items is an ArrayList.
And it gives me an error in the lambda –
Type mismatch.
Required:
Boolean
Found:
Unit
I’m new to Kotlin.
Thanks for any help
>Solution :
You need to return a Boolean value to indicate if you consumed the event or not:
lv?.setOnItemLongClickListener { _, _, i, _ ->
removeItem(i)
true
}