How to store the selected checkbox values in arraylist in android?
<p>I am working on <strong>quiz application</strong>. For each question there are <strong>multiple answers</strong> and so for that I have used <strong>checkboxes</strong>. In each page <strong>I am displaying single question with options</strong> and when next button is clicked next question will be displayed. <strong>So when multiple answers are selected by the user I need to store them in an arraylist and need to compare the selected answers with that in database.</strong> In my code I am storing the selected value id's one by one but at a time it is storing only one value. How to store all the selected checkbox id's in my arraylist?  </p>

<p>My Code:</p>

<pre><code>ArrayList&lt;String&gt; selchkboxlist;
CheckBox[] cbs;
 cbs = new CheckBox[20];
for(k=0; k&lt;List3.size(); k++)
 { 
     arr = List3.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 cb = (CheckBox) v ; 
            if (((CheckBox) v).isChecked()) {
                chk = Integer.toString(v.getId());
                    selchkboxlist = new ArrayList&lt;String&gt;();
                    selchkboxlist.add(chk);
                    Toast.makeText(Select1.this, "Selected CheckBox ID" + v.getId(), Toast.LENGTH_SHORT).show();
            } else {
                 selchkboxlist.remove(chk);
              Toast.makeText(Select1.this, "Not selected", Toast.LENGTH_SHORT).show();
                }
         }
     });
 } 
</code></pre>

<p>Please help me regarding this....Thanks in Advance</p>
