Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAshraf Ali
2,882 PointsMy checklist won't work
I've added a compound listener so I can add the integers in order to receive a score and set a xml text to it.
The score is still only giving 0. I don't know if it's because the integers are arrays(There was an error and I used alt enter to fix it, this changed to ints to arrays that are final.)
In summary, the point of this code: check if the checkbox's are ticked, when a button is pressed, and then assign 0 or 1 to it. Add them and then assign an output text to it.
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[] score = {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:
score[0]++;
break;
case R.id.faith:
score[0]++;
break;
case R.id.respect:
score[0]++;
break;
case R.id.education:
score[0]++;
break;
case R.id.community:
score[0]++;
break;
}
}
};
// adds the variables together to form a score
if(score[0] == 0){
output.setText("score of 0");
} else if(score[0] == 1){
output.setText("score of 1");
} else if(score[0] == 2){
output.setText("score of 2");
} else if(score[0] == 3){
output.setText("score of 3");
} else if(score[0] == 4){
output.setText("score of 4");
} else if(score[0] == 5){
output.setText("score of 5");
} else{
output.setText("Unknown");
}
// changes the output text based on score value
}
}