当从复选框中取消选中时,如何从数组中删除元素?

Goo*_*gle 1 android arraylist

当我在itemonsetchenge listner中取消选中复选框时,我想删除所有元素.这是我的代码

  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);    

            }        
        }

        }); 
Run Code Online (Sandbox Code Playgroud)

"checkbox_timeslot"是我的字符串数组list.i想要删除复选框中的元素是未选中的,并且从复选框列表中选中时添加项目.如何可能有帮助?

Har*_*shi 6

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);    

}
Run Code Online (Sandbox Code Playgroud)