How to simulate a button click using code?

后端 未结 7 1089
庸人自扰
庸人自扰 2020-12-04 05:27

How can I trigger a button click event using code in Android? I want to trigger the button click programmatically when some other event occurs.

Same Problem I am Fac

7条回答
  •  佛祖请我去吃肉
    2020-12-04 06:25

    If you do not use the sender argument, why not refactor the button handler implementation to separate function, and call it from wherever you want (from the button handler and from the other place).

    Anyway, it is a better and cleaner design - a code that needs to be called on button handler AND from some other places deserves to be refactored to own function. Plus it will help you separate UI handling from application logic code. You will also have a nice name to the function, not just onDateSelectedButtonClick().

提交回复
热议问题