How to simulate a button click using code?

后端 未结 7 1075
庸人自扰
庸人自扰 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

    Just write this simple line of code :-

    button.performClick();
    

    where button is the reference variable of Button class and defined as follows:-

    private Button buttonToday ;
    buttonToday = (Button) findViewById(R.id.buttonToday);
    

    That's it.

提交回复
热议问题