Here i am creating 20 Button dynamically using for loop
exmple
for(int i =1 ;i <= 20 ;i++){
Button b = new Button(this);
b.setText(String.valueOf(i));
b.setId(String.valueOf(i));
b.setBackgroudColor(Color.Red);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
b.setBackgroundColor(Color.GREEN);
}
);
}
If i select 1st Button color will be changing to green remaining all are red. similarly if i select 2nd Button 1st and 2nd button color will be green and remaining all are red. this is the way it working fine .but my requirement is if i select the any button 2nd time all buttons and previous button which i pressed color should be red. to do that i am not getting the previous button id’s. can any help for this problem
Hold a reference of the previously pressed button: