mercredi 20 avril 2016

Checkboxes and if-else statements

This is the source for a small app I'm making in Android Studio. When I call this function its suppose to compare dog,cat, and parrot to each other and then increment int dogCounter by 5. When I run the function however, It does not update the score.

dogCounter= 0;
catCounter = 0;

//check boxes
cutestCheckBoxDog = (CheckBox)findViewById(R.id.CheckboxCutestDog);
cutestCheckBoxCat = (CheckBox)findViewById(R.id.CheckboxCutestCat);
cutestCheckBoxParrot =(CheckBox)findViewById(R.id.CheckboxCutestParrot);

//call methods
processCutest(cutestCheckBoxDog, cutestCheckBoxCat, cutestCheckBoxParrot);

showResultButton= (Button)findViewById(R.id.showResults);
showResultButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {

          Toast.makeText(getApplicationContext(),catCounter +  " " + dogCounter, Toast.LENGTH_LONG).show();

public void processCutest(CheckBox dog, CheckBox cat, CheckBox parrot){


    if (dog.isChecked() && !cat.isChecked() && !parrot.isChecked()){
        dogCounter += 5;
    }else if (cat.isChecked() && !dog.isChecked() && !parrot.isChecked()){
        catCounter += 5;
    } else{
        //nobody gets points
    }
}




Aucun commentaire:

Enregistrer un commentaire