Java 我的复合听众赢了';行不通
我添加了一个复合侦听器,以便添加整数以接收分数并为其设置xml文本 比分仍然只有0分。我不知道这是否是因为整数是数组(有一个错误,我用alt enter来修复它,它改为ints to arrays,这是final) 总之,此代码的要点是:当按下按钮时,检查复选框是否勾选,然后为其指定0或1。添加它们,然后为其指定输出文本Java 我的复合听众赢了';行不通,java,android,Java,Android,我添加了一个复合侦听器,以便添加整数以接收分数并为其设置xml文本 比分仍然只有0分。我不知道这是否是因为整数是数组(有一个错误,我用alt enter来修复它,它改为ints to arrays,这是final) 总之,此代码的要点是:当按下按钮时,检查复选框是否勾选,然后为其指定0或1。添加它们,然后为其指定输出文本 package xyz.ashraf.whoisdelasalle; import android.content.Intent; import android.os.Bun
package xyz.ashraf.whoisdelasalle;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;
/**
* Created by Ashraf on 3/2/2016.
*/
public class check_Button extends Pop_sallian{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popwindow_sallian);
// Connects The variable to an xml id
TextView output = (TextView) findViewById(R.id.output);
final int[] con = {0};
final int[] fai = {0};
final int[] res = {0};
final int[] edu = {0};
final int[] com = {0};
//sets the variable to 0
OnCheckedChangeListener checkedListener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
switch(buttonView.getId()){
case R.id.concern:
con[0]++;
break;
case R.id.faith:
fai[0]++;
break;
case R.id.respect:
res[0]++;
break;
case R.id.education:
edu[0]++;
break;
case R.id.community:
com[0]++;
break;
}
}
};
int score = con[0] + fai[0] + res[0] + edu[0] + com[0];
// adds the variables together to form a score
if(score == 0){
output.setText("score of 0");
} else if(score == 1){
output.setText("score of 1");
} else if(score == 2){
output.setText("score of 2");
} else if(score == 3){
output.setText("score of 3");
} else if(score == 4){
output.setText("score of 4");
} else if(score == 5){
output.setText("score of 5");
} else{
output.setText("Unknown");
}
// changes the output text based on score value
}
}
谢谢你的帮助 你创建了一个监听器,但是你在哪里将它分配到复选框?是的,例如R.id.concern。请你解释一下,我不明白出了什么问题。