how to add and remove the selected checkbox id to and from arraylist in android?
<p>I am storing the selected checkbox value into arraylist when it is selected by the user and removing from the same arraylist when unchecked by the user. But I am having one problem with this. i.e for example I selected the checkboxes 0,1,4,6. Then I unchecked 0th checkbox. But from the arraylist 6 is removed. Next time I unchecked 1th position checkbox. But this time in from the arraylist nothing is deleted. Finally I unchecked 0 and 4 but still nothing is deleted from arraylist. The values 0,1,4 are still existing in the arraylist. How to overcome this issue?
    I want to store the selected items and remove the unselected items. Please help me regarding this....</p>

<p>My Code:</p>

<pre><code>public static ArrayList&lt;String&gt; selchkboxlist = new ArrayList&lt;String&gt;();;
String chk;  
cbs = new CheckBox[20]; 
 for(k=0; k&lt;List.size(); k++)
 { 
     arr = List.get(k);
     cbs[k] = new CheckBox(getContext());
     Rl.addView(cbs[k]);
     cbs[k].setText((CharSequence) arr.get(2));
     cbs[k].setTextColor(Color.parseColor("#000000"));  
     cbs[k].setId(k);

     cbs[k].setOnClickListener( new View.OnClickListener()
     { 
         public void onClick(View v) 
         { 
            CheckBox cbs = (CheckBox) v ;
                if (((CheckBox) v).isChecked()) {
            chk = Integer.toString(v.getId());
              selchkboxlist.add(chk);
            Toast.makeText(Myclass.this, "Selected CheckBox ID" + v.getId(), Toast.LENGTH_SHORT).show();
            System.out.println("selected checkboxes"+selchkboxlist);
            }
            else 
            {
                selchkboxlist.remove(chk);
                  Toast.makeText(Myclass.this, "Not selected", Toast.LENGTH_SHORT).show();
                  System.out.println("un selected checkboxes"+selchkboxlist);
            }
            }
            });
    }
</code></pre>

<p>Will be thankful....</p>
