我試圖獲取有多少個複選框被選中的計數,如果您取消選擇一個,則假設將計數器更新爲-1 ......所以如果我選擇4檢查盒子,它說「檢查少」=計數4 ...然後我選擇3和計數器= 3..This是我有: // ---複選框1 --- 最後CheckBox checkBox =(複選框) findViewById(R.id.checkBox1);複選框狀態android eclipse
// ---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");
}
});
}
而是使用複選框不同的變量,你可以有複選框的數組。 – noob 2012-02-22 06:29:15