title: Dynamically Add onClick ActionListener to CheckBox in Android
body: <p>I am creating an application, which creates checkboxes dynamically from the number of entries in the database.</p>
  
  <p>The code runs fine. and creates number of checkboxes. But I want to add onClick Action Listener to the CheckBoxes, dynamically. How to do this.</p>
  
  <p>I am posting the code here:</p>
  
  <pre><code>SQLiteDatabase db = this.getReadableDatabase();
  
  String countQuery = "SELECT  * FROM " + TABLE_NAME;
  SQLiteDatabase db = this.getReadableDatabase();
  Cursor cursor = db.rawQuery(countQuery, null);
  
  int maxCount = cursor.getCount();
  CheckBox[] check = new CheckBox[maxCount];
  
  cursor.moveToFirst();
  int checkboxid = 100;
  int alarm_id;
  for(int i=0;i&lt;maxCount;i++)
  {
      check[i]= new CheckBox(this);
  setCheckBoxId(i+maxCount);
  }
  </code></pre>
  
  <p>Now how to add actionlistener to these dynamically created CheckBoxes.</p>