Question

I have an Android activity with an ImageButton. I would like to execute some logic when the button is clicked and show a different image for the pressed state, but also receive the touch event on the activity.

By default only the button receives the touch event. If I set the clickable attribute of the button to false then only the activity receives the touch event.

What's the best way to implement the touch event in the activity and the click in the button?

Was it helpful?

Solution 2

For lack of a better method, I overrode the touch event on the activity to execute the activity logic and detect if the touch was over the button, in which case I change its state and invoke the onClick logic.

OTHER TIPS

Have the button call a method on the activity when it is clicked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top