Take the 2-minute tour ×

I have a button I want to simulate a click on. performClick() does most of the job, but it doesn't do the button's animation. I tried setPressed and setEnabled as well, but no dice.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Call invalidate after the setPressed to force the view to redraw:

share|improve this answer
Yep, does what I want it to--but now how do I reset it? It gets stuck in the second drawable state, and neither invalidate() a second time nor setPressed(false) seems to bring it back. –  wehweh Jul 31 '11 at 16:02
You must set it to false and then invalidate again: btn.setPressed(false); btn.invalidate(); –  Xavi Gil Jul 31 '11 at 17:52
Thanks a bunch! What I was doing wrong was putting it in the wrong place--I had to put the setpressed(false) in the ACTION_UP case, or else it executed everything to fast and you couldn't see the button change. –  wehweh Jul 31 '11 at 19:25

Try to use tool Monkey.

share|improve this answer

Your Answer


