In your XML you can use the onClick
attribute so that they all call the click method.
XML
<Button
android:id="@+id/buttonOne"
...
android:onClick="onButtonClick"/>
<Button
android:id="@+id/buttonTwo"
...
android:onClick="onButtonClick"/>
Activity
public void onButtonClick(View view) {
switch (view.getId()) {
case R.id.buttonOne: { break; }
case R.id.buttonTwo: { break; }
case R.id.buttonThree: { break; }
...
}
}
This way you can save some lines of code. Something else, depending on what functions the buttons on your screen have, you can also use a RecyclerView , which will also save you a lot of code. But this will depend on the function exerted by each button, if they are very different , I believe you to use the same code example, but if they get at the same end , you could use a RecylerView .
For example, if you want to open a screen for each button, you could use RV and depending on the button clicked, return a Bundle to open the corresponding screen, and so on.