0

我一周中的每一天都有一个:

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 被激活时,如何检查选择了哪些?

4

1 回答 1

0

创建一个成员变量Array,如

public class MyClass extends Activity
{
     ArrayList<CheckBox> cbArray = new ArrayList<CheckBox>();

然后当您创建一个复选框时,将其添加到ArrayList. 现在,当您单击删除时,Button使用 afor loop迭代ArrayList并调用isChecked()每个。然后将其删除或添加到选中Array以执行您需要的任何操作

for (int i=0; i<cbArray.size(); i++)
{
   if (cbArray.get(i).isChecked())
  {
      // do whatever here
于 2013-04-24T18:25:50.230 回答