I have dynamically created buttons. I just want change the background color of the button which I have clicked. For example, Initially all buttons should have grey background color. If I clicked a button then clicked button background color should changed to red and other buttons background color should be in grey.
Here I have tried a bit
for (int i = 0; i < 5; i++) {
Button myBtn = new Button(ProductDetailsActivity.this);
myBtn.setText("My Button"+i);
myBtn.setBackGroundColor(Color.parseColor("#cccccc"));
myBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myBtn.setBackGroundColor(Color.parseColor("#ff0000"));
}
});
}