title: Adding a Textview to a Relative Layout in Android Studio
body: <p>I have a relative layout in my XML file and it contains a button. Now I want that when I press this button, it creates 2 TextViews. Any help please because I am new to Android Studio?  I have tried creating the onClickListener for the button but I am having problems in order to get an object of the current relative layout which I have in the XML. </p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_brush_your_teeth);
  
      Intent i = getIntent();
  
      final Button addAlertButton = (Button)findViewById(R.id.AddAlert);
  
      addAlertButton.setOnClickListener(new Button.OnClickListener(){
          public void onClick(View v){
  
  
  
          }
      });
  }
  </code></pre>
  
  <p>The following is the XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout 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.user.dentalapp.BrushYourTeeth"
  tools:showIn="@layout/activity_main"&gt;
  
  &lt;!--ALERT 1--&gt;
  &lt;TextView
      android:id="@+id/Alert1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
  
      android:text="Alert 1"
      android:textSize="25dp"
      android:textAppearance="?android:attr/textAppearanceLarge"
  
      android:layout_marginTop="50dp"
      android:layout_marginLeft="50dp"/&gt;
  
  &lt;TextView
      android:id="@+id/Time1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
  
      android:text="08:00"
      android:textSize="25dp"
  
      android:onClick="showTimePickerDialog"
  
      android:layout_above="@+id/Alert2"
      android:layout_alignParentRight="true"
      android:layout_marginRight="50dp"/&gt;
  
  &lt;!--ALERT 2--&gt;
  &lt;TextView
      android:id="@+id/Alert2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
  
      android:text="Alert 2"
      android:textSize="25dp"
      android:textAppearance="?android:attr/textAppearanceLarge"
  
      android:layout_below="@id/Alert1"
      android:layout_marginTop="30dp"
      android:layout_marginLeft="50dp"/&gt;
  
  &lt;TextView
      android:id="@+id/Time2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
  
      android:text="21:00"
      android:textSize="25dp"
  
      android:layout_below="@id/Alert1"
      android:layout_marginTop="30dp"
  
      android:layout_alignParentRight="true"
      android:layout_marginRight="50dp"/&gt;
  
  
  &lt;!--ADD ALERT BUTTON--&gt;
  &lt;Button
      android:id="@+id/AddAlert"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
  
      android:text="Add Alert"
      android:textAllCaps="false"
      android:textSize="25dp"
      android:padding="15dp"
  
      android:layout_below="@id/Alert2"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="200dp"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Thanks!!</p>