user1179083
user1179083

Reputation: 79

check boxes states android eclipse

Am trying to get the count of how many check boxes are selected and if you de-select one, it's suppose to update the counter to -1......So if i select 4 check boxes and it says "check less" = count 4...then i pick 3 and the counter=3..this is what i have: // ---CheckBox 1--- final CheckBox checkBox = (CheckBox) findViewById(R.id.checkBox1);

   // ---CheckBox 2---
   final CheckBox checkBox2 = (CheckBox) findViewById(R.id.checkBox2);

   // ---CheckBox 3---

   final CheckBox checkBox3 = (CheckBox) findViewById(R.id.checkBox3);


   // ---CheckBox 4---

   final CheckBox checkBox4 = (CheckBox) findViewById(R.id.checkBox4);

   Button next = (Button) findViewById(R.id.button1);
   next.setOnClickListener(new View.OnClickListener() {
       public void onClick(View view) {
           if (checkBox.isChecked())
               count++;
           if (checkBox.isPressed())
               count--;
           if (checkBox2.isChecked())
               count++;
           if (checkBox2.isPressed())
               count--;
           if (checkBox3.isChecked())
               count++;
           if (checkBox3.isPressed())
               count--;
           if (checkBox4.isChecked())
               count++;
           if (checkBox4.isPressed())
               count--;
           if (count == pubsSelected){
           Intent myIntent = new Intent(view.getContext(), Screen2.class);
           startActivityForResult(myIntent, 0);
       }
           else if (count < pubsSelected)
               DisplayToast("Pick more pubs/holes");
           else if (count > pubsSelected)
               DisplayToast("Pick less pubs/holes");
       }

   });

}

Upvotes: 0

Views: 1309

Answers (1)

Maurice
Maurice

Reputation: 6433

I think you should do this instead:

if (checkBox.isChecked())
{
    count++;
}else
{
    count--;
}

 if (checkBox2.isChecked())
{
    count++;
}else
{
    count--;
}

Upvotes: 2

Related Questions