나는 스위치 케이스의 전체 라인을 oncheckboxclickeds에 묶어서 숫자를 합산하는 데 사용하고 있습니다.이 스위치 케이스가 작동하지 않는 이유는 무엇입니까?
마지막 줄을 제외한 모든 줄이 아름답게 작동합니다. ALL에서는 아무 것도하지 않는 것 같습니다. 그 이유를 알 수 없습니다.
이 바로 끝날 때까지, 잘 작동합니다 :
내가 프로그래밍 좀 새로운 해요package com.example.blazingboltcalculator;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
public class MainActivity extends Activity {
int attack=11;
int damage=3;
int flankAttack;
int pbs;
int justice;
int destruction;
int bane;
int DF;
int GMW;
int heroism;
int deadly;
int attackTotal;
int damageTotal;
String flames="";
String baneDice="";
String keen="";
String diceTotal;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onCheckboxClicked(View v) {
// Is the view now checked?
boolean checked = ((CheckBox) v).isChecked();
// Check which checkbox was clicked
switch(v.getId()) {
case R.id.checkBox1:
if (checked)
{
flankAttack=2;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
flankAttack=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox2:
if (checked)
{
pbs=1;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
pbs=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox3:
if (checked)
{
justice=2;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
justice=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox4:
if (checked)
{
destruction=4;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
destruction=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox5:
if (checked)
{
bane=2;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
baneDice="+2d6";
diceTotal="1d8"+baneDice+flames+keen;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
TextView textView3 = (TextView) findViewById(R.id.textView6);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
textView3.setText(diceTotal);
}
else
{
bane=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
baneDice="";
diceTotal="1d8"+baneDice+flames+keen;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
TextView textView3 = (TextView) findViewById(R.id.textView6);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
textView3.setText(diceTotal);
}
break;
case R.id.checkBox6:
if (checked)
{
DF=3;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
DF=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox7:
if (checked)
{
flames="+1d6 fire";
diceTotal="1d8"+baneDice+flames+keen;
TextView textView3 = (TextView) findViewById(R.id.textView6);
textView3.setText(diceTotal);
}
else
{
flames="";
diceTotal="1d8"+baneDice+flames+keen;
TextView textView3 = (TextView) findViewById(R.id.textView6);
textView3.setText(diceTotal);
}
break;
case R.id.checkBox8:
if (checked)
{
GMW=1;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
GMW=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox9:
if (checked)
{
heroism=2;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
heroism=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox10:
if (checked)
{
keen="+19-20 crit";
diceTotal="1d8"+baneDice+flames+keen;
TextView textView3 = (TextView) findViewById(R.id.textView6);
textView3.setText(diceTotal);
}
else
{
keen="";
diceTotal="1d8"+baneDice+flames+keen;
TextView textView3 = (TextView) findViewById(R.id.textView6);
textView3.setText(diceTotal);
}
break;
case R.id.checkBox11:
if (checked)
{
deadly=2;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
deadly=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
}
}
}
은 누구나 작품을 고무를 냄 수 있습니다 어떤 생각을 가지고 있습니까? 바로 그 마지막 사건을 제외하고는 모든 혼란이 완벽하게 작용합니다.
R.id.checkBox11과 전환 할 변수를 로깅하여 어느 시점에서 동일한 변수인지 확인하십시오. 나머지 코드를 보지 않고 무엇을 말할 지 모르겠습니다. –
'R.id.checkBox11'이 이전의 것과 중복되는 경우 각'R.id.checkBox *'의 값을 확인하십시오. 나는 그것을 의심하지만 그것은 단지 정신 건강 검사 일뿐입니다. – azhrei
약간의 연구 끝에 R.id.checkBox11 또는 변수를 기록하는 방법을 전혀 알지 못했습니다. 아니면 실제로 로그인하는 방법. 부담이되어서 미안하지만, 나는 금요일에 프로그래밍을 시작했으나 도움을 주셔서 감사합니다! –