How to call a click on a button Programatically?

By | May 9, 2018

The click on a button or View is usually called when the user clicks on it. But how can we call it programatically. Here is a simple example

Button btnClick = findViewById(R.id.btnClick);
LinearLayout mLayout = findViewById(R.id.mLayout);
 
// perform click on button
btnClick.performClick();
 
// perform click on Linear Layout
mLayout.performClick();

yes “performClick()”, this is how to call click programatically.

Leave a Reply

Your email address will not be published. Required fields are marked *