title: Android dynamically add EditText in Linear Layout
body: <p>I'm stuck trying to add an editText field dynamically under my existing editText fields using a button. Currently pressing the button does nothing. Here is my code:</p>
  
  <p><strong>XML:</strong> </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#d4cfcd"&gt;
  tools:context="com.zdowning.decisionmaker.MainActivity"&gt;
  
  
  &lt;LinearLayout
      android:id="@+id/linearLayoutMain"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:paddingLeft="16dp"
      android:paddingRight="16dp"
      android:orientation="vertical" &gt;
  
      &lt;EditText
          android:id="@+id/editText1"
          android:layout_width="match_parent"
          android:layout_height="45dp"
          android:gravity="center"
          android:hint="Enter Your Question Here"
          android:layout_marginBottom="20dp"
          android:layout_marginTop="20dp"/&gt;
  
      &lt;LinearLayout
          android:id="@+id/linearLayoutDecisions"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
      &lt;EditText
          android:id="@+id/editText3"
          android:layout_width="match_parent"
          android:layout_height="45dp"
          android:gravity="center"
          android:hint="Enter Answer #2" /&gt;
  
      &lt;EditText
          android:id="@+id/editText2"
          android:layout_width="match_parent"
          android:layout_height="45dp"
          android:gravity="center"
          android:hint="Enter Answer #1" /&gt;
  
      &lt;EditText
          android:id="@+id/editText4"
          android:layout_width="match_parent"
          android:layout_height="45dp"
          android:gravity="center"
          android:hint="Enter Answer #3" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal"
          android:gravity="center"&gt;
  
          &lt;Button
              android:id="@+id/add_button"
              style="?android:attr/borderlessButtonStyle"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@color/colorPrimary"
              android:text="+"
              android:textColor="@android:color/background_light"
              android:textSize="18sp"/&gt;
  
          &lt;View
              android:layout_width="0dp"
              android:layout_height="fill_parent"
              android:layout_weight="1" /&gt;
  
          &lt;Button
              android:id="@+id/remove_button"
              style="?android:attr/borderlessButtonStyle"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@color/colorPrimary"
              android:text="-"
              android:textColor="@android:color/background_light"
              android:textSize="18sp"
              android:layout_margin="10dp"/&gt;
      &lt;/LinearLayout&gt;
  
      &lt;RelativeLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"&gt;
      &lt;Button
          android:id="@+id/button"
          style="?android:attr/borderlessButtonStyle"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@color/colorPrimary"
          android:text="DECIDE!"
          android:textColor="@android:color/background_light"
          android:textSize="18sp"
          android:layout_centerInParent="true" /&gt;
      &lt;/RelativeLayout&gt;
  
      &lt;TextView
          android:id="@+id/textView7"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:gravity="center"
          android:layout_margin="20dp"
          android:textColor="@android:color/black"
          android:textSize="36sp" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Java:</strong></p>
  
  <pre><code>package com.zdowning.decisionmaker;
  
  import android.graphics.Typeface;
  import android.support.v7.app.AppCompatActivity;
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.Window;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  import android.widget.ScrollView;
  
  import java.lang.*;
  
  import static com.zdowning.decisionmaker.R.layout.activity_main;
  
  public class MainActivity extends AppCompatActivity {
  public int numberOfLines = 3;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  
      setContentView(activity_main);
      final Button button = (Button) findViewById(R.id.button);
      button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
               getAnswer();
          }
      });
  
      final Button Add_button = (Button) findViewById(R.id.add_button);
      button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Add_Line();
          }
      });
  }
  
  
  public void Add_Line() {
      LinearLayout ll = (LinearLayout) 
      findViewById(R.id.linearLayoutDecisions);
  
      // add edittext
      EditText et = new EditText(this);
      et.setId(numberOfLines + 1);
      ll.addView(et);
      numberOfLines++;
  }
  
  
  public void getAnswer() {
      String[] options = new String[3];
  
      EditText text = (EditText)findViewById(R.id.editText2);
      options[0] = text.getText().toString();
  
      text = (EditText)findViewById(R.id.editText3);
      options[1] = text.getText().toString();
  
      text = (EditText)findViewById(R.id.editText4);
      options[2] = text.getText().toString();
  
      int number = (int)(Math.random() * 3);
      String answer = options[number];
  
      TextView answerBox = (TextView)findViewById(R.id.textView7);
      answerBox.setText(answer);
  }
  }
  </code></pre>
  
  <p>Any advice would be a huge help as I'm brand new to android studio. Coding what is above took me hours. </p>