0

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.

Dinith Rukshan Kumara
  • 638
  • 2
  • 10
  • 19
wehweh
  • 67
  • 2
  • 14

2 Answers2

7

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

btn.setPressed(true);
btn.invalidate();
Xavi Gil
  • 11,460
  • 4
  • 56
  • 71
  • 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
0

Try to use tool Monkey.