1

こんにちは、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);    

            }        
        }

        }); 

「checkbox_timeslot」は私の文字列配列リストです。チェックボックスの要素を削除し、チェックボックスのリストからチェックしたときにアイテムを追加したいのですが、どうすればよいですか??

4

4 に答える 4

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

}
于 2012-09-19T06:51:04.517 に答える
0
     if(isChecked){

           chetimeslot = (String)chk.getTag();
           checkbox_timeslot.add(chetimeslot);

        }else{

          chetimeslot = (String)chk.getTag();
          checkbox_timeslot.remove(chetimeslot);
        }
}
于 2012-09-19T07:14:39.897 に答える
0

add(item) を使用して要素を配列リストに追加します。remove(item) リストから削除します。

chetimeslot = (String)chk.getTag();
if(isChecked){

    checkbox_timeslot.add(chetimeslot);

} else{          

    checkbox_timeslot.remove(chetimeslot);

}
于 2012-09-19T06:55:24.063 に答える