I am trying to handle touch events and click events on a button. I do the following:
button.setOnClickListener(clickListener);
button.setOnTouchListener(touc
All above answer is said that we can not handle both setOnTouchListener and setOnClickListener.
However, I see we can handle both by return false in setOnTouchListener
Example
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button = findViewById(R.id.button)
button.setOnClickListener {
Log.i("TAG", "onClick")
}
button.setOnTouchListener { v, event ->
Log.i("TAG", "onTouch " + event.action)
false
}
}
When I click at Button, logcat will display like
I/TAG: onTouch 0
I/TAG: onTouch 1
I/TAG: onClick