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.
2 Answers
Call invalidate after the setPressed to force the view to redraw:
btn.setPressed(true);
btn.invalidate();
3 Comments
wehweh
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.
Xavi Gil
You must set it to false and then invalidate again: btn.setPressed(false); btn.invalidate();
wehweh
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.