views:

379

answers:

2

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?

+1  A: 

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

CommonsWare
Unfortunately the click event handler does not have the touch object. Is it possible to reconstruct it?
hgpc
A: 

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.

hgpc