I want to create a custom onClickListener to use for databinding. This custom click listener prevents the user from spamming the button and triggering the event twice(like showing two dialogues at the same time). I made a custom listener below that works in normal code, but I don't know how to implement it for databinding like the android:onClick="" in xml.
abstract class OneClickListener(var delay: Long) : View.OnClickListener {
private var hasClicked: Boolean = true
constructor() : this(1000)
override fun onClick(it: View) {
if (!hasClicked) {
return
} else {
hasClicked = false
onClicked(it)
GlobalScope.launch {
delay(delay)
hasClicked = true
}
}
}
abstract fun onClicked(it: View)
}
Is it possible to use this listner in databinding like for example
app:OneClickListener="@{viewModel::MyMethod}" in XML? and if yes, could you please tell me how?