我添加了一个复合侦听器,因此我可以添加整数以便接收分数并为其设置xml文本。
得分仍然只给0。我不知道是不是因为整数是数组(有一个错误,我使用alt输入修复它,这改为内联到最终的数组。)
总之,此代码的要点:检查是否勾选了复选框,按下按钮,然后为其指定0或1。添加它们,然后为其分配输出文本。
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
}
}
感谢您的帮助!