title: How to Create a button with another button from a popupwindow
body: <p>I am trying to create an application which when a button from a popup window is clicked a new button will be created in another layout of the same activity.</p>
  
  <p>Here is the code for the popupwindow.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;Button
      android:id="@+id/start_goal"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/start_goal" /&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Here is the code for the activitymain.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout 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"
      tools:context="com.example.eugene.trackeruptest3.MainActivity"
      android:background="@color/darkgrey"
      android:orientation="vertical"&gt;  
  
          &lt;RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="355dp"&gt;
  
                  &lt;Button
                      android:id="@+id/setupgoal"
                      android:layout_width="350dp"
                      android:layout_height="wrap_content"
                      android:text="@string/setup_goal"
                      android:textSize="25sp" /&gt;
  
          &lt;/RelativeLayout&gt;
  
          &lt;RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:id="@+id/buttonContainer"&gt;
  
          &lt;/RelativeLayout&gt;
      &lt;/LinearLayout&gt; 
  </code></pre>
  
  <p>Here is the java code for the popupwindow</p>
  
  <pre><code>public class creategoal extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.popupwindow);
  
      DisplayMetrics dm = new DisplayMetrics();
      getWindowManager().getDefaultDisplay().getMetrics(dm);
  
      int width = dm.widthPixels;
      int height = dm.heightPixels;
  
      getWindow().setLayout((int)(width*.8),(int)(height*.6));
    }
  }
  </code></pre>
  
  <p>And here is the java code for the MainActivity.java</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      Button setupgoal = (Button) findViewById(R.id.setupgoal);
  
      setupgoal.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              startActivity(new Intent(MainActivity.this,creategoal.class));
          }
      });
    }
  }
  </code></pre>