I am finding myself in a problem where I am trying to implement a touch listener in a view. Problem is the below implementation is perfectly working on my emulator but not working on any real android device. In real device if I am pressing and holding the button it acts like click listener, fires only one time, but not working. You can find my click event implementation in below.
Note: I want to handle both click and touch listener with this implementation.
Maybe I am missing something here, can anyone please help me finding this solution?
Code
itemBinding.buttonCashOutDecrement.setOnTouchListener { _, event ->
when (event.action) {
MotionEvent.ACTION_DOWN -> {
decreaseAmountJob = lifecycleScope.launch {
while (isActive) {
decrementCashOutAmount()
delay(CASH_OUT_AMOUNT_INCREASE_DECREASE_DURATION)
}
}
}
else -> {
decreaseAmountJob?.cancel()
decreaseAmountJob = null
}
}
return@setOnTouchListener true
}