title: Dynamic list of checkboxes with onclick functions
body: <p>I have a page that returns a list of items backs from a database. I want to add each item to my android fragment as a checkbox dynamically with an onClick, that can tell if an item is being checked or un-checked. </p>
  
  <p>How can I add checkboxes dynamically with on-clicks and different titles for each?</p>
  
  <p>Below is the xml I am inserting the checkboxes into:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:background="#e5e5e5"
  
      android:layout_height="match_parent" &gt;
  
      &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical" &gt;
  
  
  
  
          &lt;FrameLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"&gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="6dp"
                  android:layout_marginRight="6dp"
                  android:layout_marginTop="4dp"
                  android:layout_marginBottom="4dp"
                  android:orientation="vertical"
                  android:background="@drawable/bg_card"&gt;
  
                  &lt;!-- Card Contents go here --&gt;
  
  
                  &lt;TextView
                      android:id="@+id/styleDescription"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:ems="10"
                      android:textSize="15sp"
                      android:padding="5dip"
  
                      &gt;&lt;/TextView&gt;
  
                  &lt;CheckBox
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="New CheckBox"
                      android:id="@+id/checkBox" /&gt;
  
  
              &lt;/LinearLayout &gt;
  
          &lt;/FrameLayout&gt;
  
          &lt;FrameLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"&gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="6dp"
                  android:layout_marginRight="6dp"
                  android:layout_marginTop="4dp"
                  android:layout_marginBottom="4dp"
                  android:orientation="horizontal"
                  android:background="@drawable/bg_card"&gt;
  
                  &lt;!-- Card Contents go here --&gt;
  
                  &lt;Button
                      android:id="@+id/buttonAddList"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="Create List"
  
                      style="?android:attr/borderlessButtonStyle"
                      android:textColor="@color/orange"
                      android:textStyle="bold"
                      /&gt;
  
  
  
  
              &lt;/LinearLayout &gt;
  
          &lt;/FrameLayout&gt;
  
  
  
  
  
  
  
      &lt;/LinearLayout&gt;
  
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>I currently have one checkbox in the above code. I plan on removing this. That checkbox is just to show where I want my check boxes to show up. </p>