title: ANDROID: Add checkbox after clicking a Button
body: <p>I'm trying to do an application that adds me new checkboxes whenever I click a button.
  Moreover the new checkbox has to take the name from the texteditor, that I already added.
  Could anyone help me?</p>
  
  <p>This is my MyAndroidAppActivity</p>
  
  <p><i></p>
  
  <pre><code> package com.example.myandroidapp;
   import android.app.Activity;
   import android.os.Bundle;
   import android.view.Menu;
   import android.view.View;
   import android.view.View.OnClickListener;
   import android.widget.Button;
   import android.widget.CheckBox;    
   import android.widget.Toast;
  
  
  public class MyAndroidAppActivity extends Activity {
  
  private CheckBox chkIos, chkAndroid, chkWindows;
  private Button btnDisplay, btn_add;
  public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      addListenerOnChkIos();
      addListenerOnButton();
  
  }
  
  
  
  public void addListenerOnChkIos() {
  
      chkIos = (CheckBox) findViewById(R.id.chkIos);
  
      chkIos.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
  
              if (((CheckBox) v).isChecked()) {
                  Toast.makeText(MyAndroidAppActivity.this,
                          "Bro, try Android :)", Toast.LENGTH_LONG).show();
              }
  
          }
      });
  
  }
  
  public void addListenerOnButton() {
  
      chkIos = (CheckBox) findViewById(R.id.chkIos);
      chkAndroid = (CheckBox) findViewById(R.id.chkAndroid);
      chkWindows = (CheckBox) findViewById(R.id.chkWindows);
      btnDisplay = (Button) findViewById(R.id.btnDisplay);
  
      btnDisplay.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
  
              StringBuffer result = new StringBuffer();
              result.append("IPhone check : ")
                      .append(chkIos.isChecked());
              result.append("\nAndroid check : ").append(
                      chkAndroid.isChecked());
              result.append("\nWindows Mobile check :").append(
                      chkWindows.isChecked());
  
              Toast.makeText(MyAndroidAppActivity.this, result.toString(),
                      Toast.LENGTH_LONG).show();
  
          }
      });
  
  }
  
  }
  </code></pre>
  
  <p></i></p>
  
  <p>and this is main.xml</p>
  
  <p><i></p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical" 
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"&gt;
  
  
  
    &lt;EditText
  
     android:id="@+id/edit_message"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:ems="10"
     android:hint="@string/edit_message" /&gt;
  
    &lt;requestFocus /&gt;
  
  
  
  
    &lt;Button
        android:id="@+id/btn_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_add" /&gt;
  
  &lt;CheckBox
      android:id="@+id/chkIos"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/chk_ios" /&gt;
  
  &lt;CheckBox
      android:id="@+id/chkAndroid"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:checked="true"
      android:text="@string/chk_android" /&gt;
  
  &lt;CheckBox
      android:id="@+id/chkWindows"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/chk_windows" /&gt;
  
  &lt;Button
      android:id="@+id/btnDisplay"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/btn_display" /&gt;  
  </code></pre>
  
  <p>
  </i></p>