You can set the onClickListener for each button. Use the button identifier from the view.getId() method using the view.getId() method to identify the button click.
You can add separate listeners for each button, as here (provided that the identifier that you set for each button matches the line)
minusButton.setOnClickListener(new View.OnClickListener(){ public void onClick(View v){
Edit:
I assume your code is like this. Correct me if there is a deviation.
Button minusButton = null; for(int i = 0; i < rowCount; i++) { minusButton = new Button(this); minusButton.setId(i); // set other stuff and add to layout minusButton.setOnClickListener(this); }
Let your class implement the View.OnClickListener interface and implement the onClick() method.
public void onClick(View v){
source share