How to properly use setOnLongClickListener() with Kotlin

This one also works for Kotlin. Simply return true

view.setOnLongClickListener {
    Toast.makeText(this,"This is a long click",Toast.LENGTH_SHORT).show(); 
    true
}

Another way can be this...

view.setOnLongClickListener{
    dispathAnEventOnLongClick("Long click detected!");
}
private fun dispathAnEventOnLongClick(text:CharSequence): Boolean {
    Toast.makeText(applicationContext,text,Toast.LENGTH_SHORT).show();
    return true;
}

OnLongClickListener.onLongClick signature required that you return a boolean to notify if you actually consumed the event

view.setOnLongClickListener{
     Toast.makeText(this, "Long click detected", Toast.LENGTH_SHORT).show()
     return@setOnLongClickListener true
}

or

view.setOnLongClickListener{
     Toast.makeText(this, "Long click detected", Toast.LENGTH_SHORT).show()
     true
}