对于这个简单的问题,我很抱歉,但我必须做错事,
如果选中一个复选框,我有12个复选框,整数需要增加固定值(取决于框)并显示在textView
当我选中一个方框时,它没有显示它所假设的值 - refurbCost在构造函数中初始化为0,并且在没有选中框时显示为0
当我选择新厨房时显示为21300而不是3000
我做错了什么 - p.s我知道代码可能不是很好的练习我在Android开发中仍然很新
码
public void onClick(View v) {
boolean checked = ((CheckBox) v).isChecked() ;
switch (v.getId()){
case R.id.centralHeating:
if(checked) {
refurbCost += 2750;
}
case R.id.newKitchen:
if(checked) {
refurbCost += 3000;
}
case R.id.newBathroom:
if(checked) {
refurbCost += 1000 ;
}
case R.id.reWire:
if(checked) {
refurbCost += 2500;
}
case R.id.windowDoors :
if(checked) {
refurbCost += 3000;
}
case R.id.stairsBanisters:
if(checked) {
refurbCost += 2000;
}
case R.id.carpets:
if(checked) {
refurbCost += 2000;
}
case R.id.garden:
if(checked) {
refurbCost += 1000;
}
case R.id.wallCeiling:
if(checked) {
refurbCost += 1000;
}
case R.id.decoration:
if(checked) {
refurbCost += 1200;
}
case R.id.alarmSys:
if(checked) {
refurbCost += 600;
}
case R.id.fireSafety:
if(checked) {
refurbCost += 4000;
}
refurbTotal.setText(""+refurbCost);
}
答案 0 :(得分:5)
每个案例陈述后你必须break
e.g。
case blabla: doSmth(); break;
答案 1 :(得分:1)
中断;缺少
case R.id.carpets:
if(checked) {
refurbCost += 2000;
}
break;