2011-05-16 3 views
0

두 번째 클릭 후 버튼 1에서 버튼 2로 색상을 전환하는 방법은 무엇입니까? 다음은 제 2 버튼 당신은 당신의 청중에 lCount 및/또는 rCount를 증가되지만,이 패리티 myCount을 테스트두 번째 버튼 클릭 후 색상 전환

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); 
    } 
}); 
+0

'&'는 비트 연산자입니다. lCount와 rCount를 추가하려고합니까? 대신에'lCount + rCount'를 사용해야합니다. – kcoppock

답변

1

을 클릭합니다. 그것이 사물이 변화하지 않는 이유입니다.

+0

이것은 개인 int입니다 : 'private int lCount = 0; 개인 int rCount = 0; int int myCount = lCount & rCount; ' ** switch 문을 사용하는 방법 ** – HunterX86

+0

'mycount = lCount & rCount' 정의는'myCount'를 ** 변경하지 않는 값으로 설정합니다 ** 왜냐하면'lCount' 및/또는'rCount'가 변경됩니다. 나는 당신이 함수'int myCount() {return lCount & rCount; }'대신 사용하십시오. 아니면 그냥'((lCount & rCount) % 2 == 0)'에 대해서 테스트해라. –

+0

이제 스위치 문을 사용하고 싶습니다. 내가 어떻게 그럴 수 있니? – HunterX86

0

왜 이렇게 해보지 않으시겠습니까?

private int lCount = 0; 
private int rCount = 0; 
private int myCount = 0; 

final TextView countTextViewPlusL = (TextView) findViewById(R.id.TextViewCountL); 
final Button countButtonPlusL = (Button) findViewById(R.id.ButtonCountPlusL); 
final TextView countTextViewPlusR = (TextView) findViewById(R.id.TextViewCountR); 
final Button countButtonPlusR = (Button) findViewById(R.id.ButtonCountPlusR); 

View.OnClickListener listener = new View.OnClickListener() { 
    public void onClick(View v) { 
     switch(v.getId()) { 
      case R.id.ButtonCountPlusR: 
       rCount++; 
       break; 
      case R.id.ButtonCountPlusL: 
       lCount++; 
       break; 
     } 
     myCount = lCount + rCount; 
     if(myCount % 2 == 0) { 
      //invert colors here 
     } 
    } 
}); 

countButtonPlusL.setOnClickListener(listener); 
countButtonPlusR.setOnClickListener(listener); 

다음은 두 번째 클릭인지 확인 후, 왼쪽과 오른쪽 카운터의 합계 반 환 같게 설정, 각각 클릭 된 버튼을 클릭하여 해당 카운터를 증가 확인, 모든 카운터를 0으로 초기화한다. 그 체크 내에서 TextView 색상을 뒤집습니다.

+0

마지막 행에 오류가 발생합니다. ";" '이 줄에 여러 마커가 있습니다 \t - 구문 오류, 완료하려면 "}"을 입력하십시오. \t - 구문 오류, 삽입 ";" FieldDeclaration을 완료하려면 \t - 구문 오류, "}"을 (를) 입력하여 ClassBody를 완성하십시오. . 그리고 마지막으로 "}"토큰에 구문 오류가 발생했습니다.}} ", {expectedy – HunterX86

+0

} 괄호와 세미콜론을 사용하지 않았습니다. 지금 시도해보십시오. – kcoppock

+0

정확히 여기에 파일을 넣어야합니까? // 여기에 색상을 반전하십시오. 및 방법은 무엇입니까 – HunterX86

관련 문제