我每周的每一天都有其中一个:
mondayRadioButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mondayRadioButton.isChecked()){
deleteAppointmentsLayout.removeAllViews();
daySelected = 1;
for(Iterator<Appointment> i = appointments.iterator(); i.hasNext();){
Appointment item = i.next();
if(item.getDay() == 1){
checkBox = new CheckBox(DeleteAppointmentActivity.this);
System.out.println("fucken did work");
id = item.getId();
time = item.getTime();
duration = item.getDuration();
description = item.getDescription();
boxText = time + ", " + duration + ", " + description;
checkBox.setText(boxText);
checkBox.setTextSize(12);
checkBox.setId((int) id);
deleteAppointmentsLayout.addView(checkBox);
}
else {
System.out.println("fucken didnt work");
}
}
}
}
});
当激活按钮的onclick时,我想检索当前所选日期的每个所选复选框的信息(复选框是以编程方式生成的)。当激活删除按钮的onclick时,如何检查选择了哪些?
答案 0 :(得分:0)
创建一个成员变量Array
,如
public class MyClass extends Activity
{
ArrayList<CheckBox> cbArray = new ArrayList<CheckBox>();
然后在创建复选框时将其添加到ArrayList
。现在,当您点击删除Button
时,请使用for loop
来迭代ArrayList
并在每个isChecked()
上调用Array
。
然后将其删除或添加到已选中的for (int i=0; i<cbArray.size(); i++)
{
if (cbArray.get(i).isChecked())
{
// do whatever here
,以便随身携带
{{1}}