I have a button in android application that has an accompanying red-circle TextView
that represents a counter (iOS-style):
Button is a StateListDrawable
so that when pressed is (visually) goes slightly down. I want accompanying red circle to go down as well.
I would be happy if I could found a callback that tells me when the button goes to pressed or unpressed (normal) state. I tried btn.setOnTouchListener
, but it does not work. For instance, when I press button, it fires MotionEvent.ACTION_DOWN
and that's good. But if I drag my finger out of button, it jumps back to normal state, but MotionEvent.ACTION_UP is not fired until I release my finger.
You have two ways to do this
Include
Button
andTextView
in one layout and set click listener to that layout.Perform
TextView
click insideButton
click listener. see below code.