如何在第二次單擊後使用「開關語句」將按鈕1的顏色切換爲按鈕2? 這些都是我的2個按鈕的點擊第二個按鈕單擊後的顏色開關
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);
}
});
'&'是一個按位運算符。你想添加lCount和rCount嗎?您應該使用'lCount + rCount'來代替。 – kcoppock 2011-05-16 20:33:22