check all or uncheck all dynamically created checkboxes in android
<p>1.here all my code.
2.for create dynamic checkbox for check or uncheck all checkboxes<br>
    {  final String[][] itemContainer = new String[30][7];
    TableLayout tblItemDetail;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_item_code_release);
    tblItemDetail = (TableLayout)findViewById(R.id.tblItemDetail);<br>
    try {
    sqlItem = "";
    sqlItem = "SELECT  * from itm_mst";
    rs = objDbConnect.getResultSet(sqlItem);
    if (rs.next()) {
    int  i1 = 1;
    do {
    itemContainer[itemCount][0]=Integer.toString(i1++);
    itemContainer[itemCount][6]="N"; //checkbox value
    itemCount++;
    } while (rs.next());
    tblItemDetail.removeAllViews();
    if (itemCount > 0) {</p>

<pre><code>CheckBox tvchkall = new CheckBox(ItemCodeRelease.this);  //header row checkbox for ckeck or uncheck all checkbox
tvchkall.setGravity(Gravity.CENTER);
tvchkall.setPadding(20, 0, 20, 0);
tvchkall.setText("Y");
headerRow1.addView(tvchkall);
tvchkall.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(buttonView.isChecked())
 {                              
 for(int a = 0 ; a &lt; itemContainer.length ; a++)
 {
   for(int b = 0 ; b &lt; itemContainer[a].length ; b++)
    {
       CheckBox chkb = (CheckBox)tblItemDetail.findViewById(a);
       if ( chkb == null )
       continue;
       chkb.setChecked(true);
   Log.i("Checkbox serrch","checked  "+chkb.getText()+"ID +chkb.getId());
   if(a == chkb.getId())
    {
      itemContainer[a][6] = "Y";
    }
      else
    {
     Log.i("Checkbox serrch","unchecked"+chkb.getText()+"ID  "+chkb.getId());
    itemContainer[a][6] = "N";
     }}}}
     });
     tblItemDetail.addView(headerRow1);
     int alternateRow1 = 0;
      for (i = 0; i &lt; itemCount; i++) {
       TableRow bodyRow1 = new TableRow(ItemCodeRelease.this);
       if (alternateRow1 % 2 == 0) {
          bodyRow1.setBackgroundResource(R.color.statusalternateRow);
      }
      else {
      bodyRow1.setBackgroundResource(R.color.statusRow);
          }
      final CheckBox cb1 = new CheckBox(ItemCodeRelease.this);   //body row of checkbox
      cb1.setId(i);
      cb1.setGravity(Gravity.CENTER);
       cb1.setPadding(20, 0, 20, 0);
      bodyRow1.addView(cb1);
      cb1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
       @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
          // TODO Auto-generated method stub
         for(int a = 0 ; a &lt; itemContainer.length ; a++)
            {
             for(int b = 0 ; b &lt; itemContainer[a].length ; b++)
              {
                   if(buttonView.isChecked())
                   {
                     Log.i("Checkbox serrch","checked  "+buttonView.getText()+"ID  "+buttonView.getId());
                    if(a == buttonView.getId())
                    {
                        itemContainer[a][6] = "Y";
                          continue;
                     }}
                     else
                    {
                       itemContainer[a][6] = "N";
                      }}}}
                     });
                     bodyRow1.addView(tvBodySRNo1);
                     tblItemDetail.addView(bodyRow1);       
                     alternateRow1++;
               }}} 
               } catch (Exception e) {      e.printStackTrace();                      }}
</code></pre>