你好,当我在itemonsetchenge列表器中取消选中复选框时,我想删除元素。
这是我的代码

  checkbox_timeslot.clear();

          chk.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO Auto-generated method stub

                String chetimeslot;

                if(isChecked){

                chetimeslot = (String)chk.getTag();
                checkbox_timeslot.add(chetimeslot);
                Log.e("array value", ""+checkbox_timeslot);
                Log.e("checked slo value", ""+chetimeslot);

                }else{

                checkbox_timeslot.add("");
                Log.e("else array value", ""+checkbox_timeslot);

            }
        }

        });


“ checkbox_timeslot”是我的字符串数组列表。我想取消选中复选框中的元素,并在从复选框列表中选中时添加项目。如何提供帮助?

最佳答案

if(isChecked){

    chetimeslot = (String)chk.getTag();
    checkbox_timeslot.add(chetimeslot);
    Log.e("array value", ""+checkbox_timeslot);
    Log.e("checked slo value", ""+chetimeslot);

} else{

     chetimeslot = (String)chk.getTag();
     checkbox_timeslot.remove(chetimeslot);
     Log.e("else array value", ""+checkbox_timeslot);

}

10-08 18:18