How can I trigger a button click event through code in Android? Basically, I want to trigger the button click programmatically when some other event occurs. thank you
Asked
Active
Viewed 2,405 times
0
-
2Why don't you just call your method containing your business logic "when some other event occurs"? – CommonsWare May 13 '13 at 13:53
-
1button.perfomClick() use this when you receive a certain order to perfom click on button. @CommonsWare has a valid point. – Raghunandan May 13 '13 at 13:53
-
@CommonsWare because the button has some animations to be done. – Mohammad Shour Oct 21 '22 at 13:04
1 Answers
0
We need a bit more to go on than this, which button do want to emulate being pressed when the event is triggered?
For example if you want to press the back button you can just call
onBackPressed();
inside your activity, other button actions might require more complex calls.
or if you want to press one of the buttons you have created inside your layout you can call
button.performClick();

Aedis
- 413
- 3
- 6