флажки состояния Android затмение - PullRequest
0 голосов
/ 22 февраля 2012

Пытаюсь подсчитать, сколько флажков выбрано, и если вы отмените выбор одного из них, предполагается обновить счетчик до -1 ...... Так что, если я выберу 4 флажка, и он говорит "проверить меньше "= количество 4 ... тогда я выбираю 3 и счетчик = 3. Это то, что у меня есть: // --- CheckBox 1 --- окончательный 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");
       }

   });

}

1 Ответ

2 голосов
/ 22 февраля 2012

Я думаю, что вы должны сделать это вместо:

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

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