Q:

How to get the id's of selected checkboxes which are displaying dynamically in android?

In my project I am displaying the checkboxes dynamically. But I want to get the id values of all the checkboxes that are selected. In my application the user will select multiple checkboxes and I need to store those selected checkboxes id's in an arraylist. How can I get the selected checkboxes id's?
My Code:
 public View getView(int position, View convertView, ViewGroup parent) 
{
  View view = convertView;
  try
  {
  if (view == null) 
   {
    LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = vi.inflate(R.layout.list_item1, null); 
    }
    final UserBO listItem = mList.get(position);            
    if (listItem != null) 
      {

    Rl = (LinearLayout)findViewById(R.id.chklnlayout);

    ArrayList<UserBO> mList1;

    CheckBox[] cbs = new CheckBox[20]; 

    for(int k=0; k<list.size(); k++)
    { 
     System.out.println("list in for loop"+list.get(0));
     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"));  
    } 

   }
}
catch(Exception e){
  String err = (e.getMessage()==null)?"hii":e.getMessage();
  Log.e("sdcard-err2:",err);  
}
return view;
}

Please help me regarding this....Thanks in Advance

A:

In your code for loop,
Write this line,
cbs[k].setId(k);

Now implements OnClickListener in your activity
in 
@Override
public void onClick(View v)
{
int checkBoxId  = v.getId();    
}

or something like,
@Override
    public void onClick(View v)
    {
        // Perform action on clicks, depending on whether it's now checked
        if (((CheckBox) v).isChecked()) {
            Toast.makeText(Activity.this, "Selected CheckBox ID" + v.getId(), Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(Activity.this, "Not selected", Toast.LENGTH_SHORT).show();
        }
}

And let me know what happen..

