how can i use the “switch statement” to switch the colors from button 1 to button 2, after the 2nd click?
these are my 2 button clicks
private int lCount = 0;
private int rCount = 0;
private int myCount = lCount & rCount;
final TextView countTextViewPlusL = (TextView) findViewById(R.id.TextViewCountL);
final Button countButtonPlusL = (Button) findViewById(R.id.ButtonCountPlusL);
countButtonPlusL.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
myCount++;
if(myCount%2 == 0){
countTextViewPlusL.setBackgroundColor(0xffffffff);}
else countTextViewPlusL.setBackgroundColor(0x00000000);
lCount++;
if (lCount >-1)
countTextViewPlusL.setText("" + lCount);
}
});
final TextView countTextViewPlusR = (TextView) findViewById(R.id.TextViewCountR);
final Button countButtonPlusR = (Button) findViewById(R.id.ButtonCountPlusR);
countButtonPlusR.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
myCount++;
if(myCount%2 == 0){
countTextViewPlusR.setBackgroundColor(0xffffffff);}
else countTextViewPlusR.setBackgroundColor(0x00000000);
rCount++;
if (rCount >-1)
countTextViewPlusR.setText("" + rCount);
}
});
You are incrementing
lCountand/orrCountin your listeners, but you are testingmyCountfor parity. That’s why things don’t change.