I'm trying to get rid of a warning where Android Studio wants my onTouchListener to override performClick which I do, but the warning remains.
draggableBar!!.setOnTouchListener(View.OnTouchListener { view, motionEvent ->
when (motionEvent.getAction()) {
MotionEvent.ACTION_DOWN -> {
}
MotionEvent.ACTION_UP -> {
view.performClick()
}
}
return@OnTouchListener true
})
Could this be an Android Studio bug or am I doing something wrong?
Okay, I have the same problem but i fixed it by overriding the onTouch listener.
The default onTouch wants us to override performClick(), but this does not work even calling the method by view.performClick().
So therefore override your onTouch like this:
override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
when (view) {
draggableBar -> {
when (motionEvent.getAction()) {
MotionEvent.ACTION_DOWN -> {
}
MotionEvent.ACTION_UP -> {
view.performClick()
}
}
}
otherButtonHere -> {
//your welcome
}
}
return true
}
And in that way, you can use single onTouch() in all clickable views you have.
Don't forget to implement to your Class:
View.OnTouchListener
And set the listener:
draggableBar!!.setOnTouchListener(this)
HOPE IT HELPS! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With