I am working on a ANDROID project and in it I have multiple buttons.
REQUIREMENT:-
1.When I click on a button once I want it to change to green color and when I click on same button again I want it to change back to original color.
2.When a button is selected(i.e. color becomes GREEN) I want to add a number to a array list and when I select it once again I want to remove the added number from the list.
I have come up with this solution as of now. But it doesn't work.
int flag=1;
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
flag+=1;
if(flag%2==0) {
SeatArrayList.remove(Integer.valueOf(1));
button1.setBackgroundColor(Color.GREEN);
}
else{
SeatArrayList.add(1);
button1.setBackgroundColor(bg_yellow);
}
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
flag+=1;
if(flag%2==0) {
SeatArrayList.remove(Integer.valueOf(3));
button3.setBackgroundColor(Color.GREEN);
}
else{
SeatArrayList.add(3);
button3.setBackgroundColor(bg_yellow);
}
}
});
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
flag+=1;
if(flag%2==0) {
SeatArrayList.remove(Integer.valueOf(4));
button4.setBackgroundColor(Color.GREEN);
}
else{
SeatArrayList.add(4);
button4.setBackgroundColor(bg_yellow);
}
}
});