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 trial


Ashraf Ali
Ashraf Ali
2,882 Points

My 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{
    protected void onCreate(Bundle savedInstanceState) {
        // 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() {

            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    case R.id.concern:
                    case R.id.faith:
                    case R.id.respect:
                    case R.id.education:
                    case R.id.community:

        // 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{
        // changes the output text based on score value