【问题标题】:check boxes states android eclipse复选框状态 android eclipse
【发布时间】:2012-03-12 10:13:47
【问题描述】:

我正在尝试获取选中的复选框的数量,如果您取消选择一个,则假设将计数器更新为 -1......所以如果我选择 4 个复选框并且它显示“少检查” = 计数 4 ......然后我选择 3 并且计数器 = 3 ..这就是我所拥有的: // ---复选框 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");
       }

   });

}

【问题讨论】:

  • 您可以拥有一个 CheckBox 数组,而不是为 CheckBox 使用不同的变量。

标签: android eclipse radio-button checkbox


【解决方案1】:

我认为你应该这样做:

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

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

【讨论】:

  • @Maurice 如果我的CheckBox 号码在我的ListView 中是未知的,我该怎么办,因为它是动态的。我怎么知道在哪里检查checkBoxNumber.isChecked()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-30
  • 2011-07-01
  • 1970-01-01
  • 2016-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多